New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type spec lost on a class field when the imported type is overridden by another import #35613

Open
aabdagic opened this Issue Jan 9, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@aabdagic
Copy link

aabdagic commented Jan 9, 2019

This example will fail to compile with no-implicit-casts:

import 'dart:ui';

import 'package:flutter/painting.dart';

class MyTextStyles {
  TextStyle aTextStyle = TextStyle();

  void main() {
    frombulate(aTextStyle);
  }

  void frombulate(TextStyle t) {}
}

because MyTextStyles.aTextStyle is believed to be dynamic.

I have only been able to repro this when:

  • Referring to aTextStyle as a class field. Be that an instance field on the current or different class, or a static. Top-level fields don't seem to have a problem. And neither do locals.
  • When the type (in the example TextStyle) is imported "twice". Both "package:flutter/painting.dart" and "dart:ui" define one. Adding show to import 'package:flutter/painting.dart' doesn't change anything, but removing TextStyle import from dart:ui (by showing only different types) does resolve this.
@aabdagic

This comment has been minimized.

Copy link

aabdagic commented Jan 9, 2019

Also, using

final aTextStyle = TextStyle();

avoids the bug...

@lrhn

This comment has been minimized.

Copy link
Member

lrhn commented Jan 9, 2019

This is definitely a bug.

The two imports refer to two different TextStyle classes. That means that any reference to TextStyle should be a compile-time error, the name is introduced twice into the same scope, so you can't meaningfully refer to it.

In Dart 1 it just made the type malformed. Dart 2 has no malformed types, just compile-time errors.

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