Open
Description
Versions:
- DartPad on SDK 2.7.0
- VM/dart2js/DDC on 2.8.292505767-edge+google3-v2 (google3)
Here's a working reproduction https://dartpad.dev/a8a92c56149499dd479488f1cca5bff9.
class Value {}
class Renderer<T> {}
// When V is defined before R, type inference works in all cases.
class WorkingOrder<V extends Value, R extends Renderer<V>> {}
// When V is defined after R, type inference fails in some cases.
class BrokenOrder<R extends Renderer<V>, V extends Value> {}
void main() {
// Correctly infers type.
var working1 = WorkingOrder();
print(working1.runtimeType); // WorkingOrder<Value, Renderer<Value>>.
// Correctly infers type arguments to bounds.
WorkingOrder working2 = WorkingOrder();
print(working2.runtimeType); // WorkingOrder<Value, Renderer<Value>>.
// ERROR: Incorrectly infers BrokenOrder<Renderer<dynamic>, Value>.
var broken = BrokenOrder();
// Correctly infers type arguments to bounds.
BrokenOrder working3 = BrokenOrder();
print(working3.runtimeType); // BrokenOrder<Renderer<Value>, Value>.
}
- Inference behaves differently when inferring the type of a variable declared as
var
versus the raw type - this is unexpected. - The inference algorithm used for inferring the type of a variable declared as
var
appears to be dependent on the order in which type parameters are declared on the resulting type, when one of those type parameters depends on the other.
Metadata
Metadata
Assignees
Labels
A lower priority bug or feature requestFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.Contributions welcome to help resolve this (the resolution is expected to be clear from the issue)Issues with the analyzer's implementation of the language specLegacy: Use area-dart-model instead.Incorrect behavior (everything from a crash to more subtle misbehavior)