HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.18k stars 655 forks source link

[display] no expected-type completion for (Map) array-assignment #8038

Open nadako opened 5 years ago

nadako commented 5 years ago
class Main {
    static function main() {
        var x = new Map<String, {f:Int}>();
        x[""] = |
    }
}

no {fields...} 😢

Works with Array, didn't test with custom/non-multiType abstracts, but I suspect it's a general abstract operator overloading issue. Could we at least provide the expected type when there's only one @:op([])?

Gama11 commented 5 years ago

Multiple expected types could in theory be represented as haxe.extern.EitherType, but that's probably too hacky? :) The language server already looks for that, but it doesn't tend to work very well because of #7262.

Simn commented 5 years ago

This is not actually an issue specific to completion. We don't apply top-down inference in these cases because the order is inverse: We type the operands of the array access, then find the appropriate field on the abstract.

We could type the index expression and then filter those array-access-write functions which accept its type as the first argument. This would make something like this work too:

class Main {
    static function main() {
        var x = new Map<String, Array<Dynamic>>();
        x[""] = [1, "foo"];
    }
}