Skip to content

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

Closed

Description

@DartBot

This issue was originally filed by rodion...@unipro.ru


What steps will reproduce the problem?

  1. Run this test with --component=dartc:
    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);
}

  1. Observe the errors

What is the expected output? What do you see instead?
Spec says (Ch. 7.7):
A non-fi nal 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

Activity

  1. floitschG commented on Nov 29, 2011

    @floitschG
    Contributor

    Added Area-Compiler, Triaged labels.

  2. DartBot commented on Mar 28, 2012

    @DartBot
    Author

    This comment was originally written by zundel@google.com


    Just ran this test again, this is a problem with static analysis, not code generation.

  3. kasperl commented on Apr 17, 2012

    @kasperl

    Removed Area-Compiler label.
    Added Area-Analyzer label.

  4. danrubel commented on Jun 4, 2012

    @danrubel

    Added this to the M1 milestone.

  5. DartBot commented on Jun 6, 2012

    @DartBot
    Author

    This comment was originally written by zundel@google.com


    Just ran the above test again and there are no errors output.


    Added CannotReproduce label.

  6. DartBot commented on Jun 7, 2012

    @DartBot
    Author

    This comment was originally written by rodion...@unipro.ru


    Just checked with a recent build of dartc and there was no error as well.
    Looks like it's been fixed at some point

  7. added this to the M1 milestone on Jun 7, 2012
  8. added a commit that references this issue on Aug 31, 2016
    9b421eb
  9. added a commit that references this issue on Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions