-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent interface type inference for getters/setters #11774
Comments
What's wrong with that? Getter and setter are implementation details compatible with the contract as long as Void->Int is a subtype of Void->Float, covariance stuff and all... class Test {
static function main() {
var myFunc:Void->Float = foo;
}
static function foo():Int {
return 0;
}
} Main is also a subtype of IObj with its own width:Int, as long as read-only access is covariant on the return type. |
Yes, i think implementing Float as Int should be allowed, this is pretty handy for subclasses to restrict Float a little. But it doesn't work in all cases, only for interface IMain {
var a(default, never):Float;
var b(default, null):Float;
var c:Float;
var d(get, set):Float;
}
class Main implements IMain {
public var a:Int = 0; // fine, good
public var b:Int = 0; // fine, good
public var c:Int = 0; // Field c has different type than in IMain
public var d(get, set):Int; // Field d has different type than in IMain
function get_d():Int
return 0;
function set_d(d:Float):Int
return 0;
static function main() {
final main = new Main();
// Allowed because there is no `a(default, never)` in Main, bad
main.a = 1;
}
public function new() {}
} And there is another bug, you can have more restricted type in interface with |
It should work for read access only. In case of write access relation is also a contravariant so subtyping is impossible. |
The text was updated successfully, but these errors were encountered: