skew icon indicating copy to clipboard operation
skew copied to clipboard

Failing type-check for abstract getters

Open mindplay-dk opened this issue 9 years ago • 2 comments

I have an abstract base-class with an abstract, generic getter named value.

class Foo<T> {
  def value T
}

I extend this into a generic class with a generic private field _value and a constructor - but when I try to implement the value getter, it fails:

class Bar<T> : Foo<T> {
  var _value T
  def value T { # error: "value" overrides another function with the same name and argument types but a different return type in base type "Foo<T>"
    return _value
  }
  def new(value T) {
    super
    _value = value
  }
}

I was hoping to be able to do something like:

class Baz : Bar<string> {}

var baz = Baz.new("hello")

Am I doing something wrong or is this a (current?) limitation of generic type-checks?

mindplay-dk avatar Jan 15 '17 12:01 mindplay-dk

Hello mindplay ! Looking at other skew classes I could see that it seems to use the "over" in front of methods to indicate that we are overridden a base method. Maybe this is the problem ?

  class CSharpTarget : CompilerTarget {
    over name string { return "C#" }
    over extension string { return "cs" }
    over stopAfterResolve bool { return false }
    over requiresIntegerSwitchStatements bool { return true }
    over supportsListForeach bool { return true }
    over supportsNestedTypes bool { return true }
    over stringEncoding Unicode.Encoding { return .UTF16 }
    over editOptions(options CompilerOptions) { options.define("TARGET", "CSHARP") }
    over includeSources(sources List<Source>) { sources.prepend(Source.new("<native-cs>", NATIVE_LIBRARY_CS)) }
    over createEmitter(context PassContext) Emitter { return CSharpEmitter.new(context.options, context.cache) }
  }

mingodad avatar Feb 16 '17 00:02 mingodad

@mingodad no, it doesn't look like that's the problem.

The base method in my example doesn't have a body, which makes it abstract, as far as I understand. Using over instead of def actually produces an additional error message:

error: "value" is declared using "over" instead of "def" but does not override anything

According to the error message, it doesn't override anything, which suggests as I assumed that that a getting without a body is abstract.

So I don't think that's it.

mindplay-dk avatar Feb 16 '17 20:02 mindplay-dk