Static variable declaration of the form "static var v = X" prevents further assigments to v if the value's type is not assignable to X's type #627
Labels
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
closed-cannot-reproduce
Closed as we were unable to reproduce the reported issue
Milestone
This issue was originally filed by rodion...@unipro.ru
What steps will reproduce the problem?
class A {
static var b = 1;
}
main() {
A.b = -1;
Expect.equals(-1, A.b);
A.b = "bar";
Expect.equals("bar", A.b);
Map bar = new Map<String, int>();
A.b = bar;
Expect.equals(bar, A.b);
}
What is the expected output? What do you see instead?
Spec says (Ch. 7.7):
A non-final static variable declaration of the form static T v; or the form static T v = e; always induces an implicit static setter function (7.3) with signature
static void set v(T x)
whose execution sets the value of v to the incoming argument x.
Doesn't say the setter's argument type is fixed to the runtime type of e, Dynamic is implied and a value of any type should be possible to use.
What version of the product are you using? On what operating system?
latest Dart version, ubuntu 2.6.32-35-generic
The text was updated successfully, but these errors were encountered: