Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

task model: override inference not working for final fields when subtype narrows the type #348

Closed
jmesserly opened this issue Sep 24, 2015 · 1 comment
Assignees

Comments

@jmesserly
Copy link
Contributor

  testChecker(
      'infer from RHS only if it wont conflict with overridden fields 2',
      {
        '/main.dart': '''
        class A {
          final x;
        }

        class B extends A {
          final x = 2;
        }

        foo() {
          String y = /*severe:StaticTypeError*/new B().x;
          int z = new B().x;
        }
    '''
      },
      inferFromOverrides: true);

Naturally non-final fields need to be invariant. But subtypes should be allowed to narrow final fields, right? The test above expects B.x to be inferred as int because that doesn't violate the contract of A.x

@jmesserly
Copy link
Contributor Author

https://codereview.chromium.org/1367183004 is the fix. It seems harmless to infer here but a bit ad hoc

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant