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

type promotion stops working in some cases with inference #343

Closed
jmesserly opened this issue Sep 22, 2015 · 2 comments
Closed

type promotion stops working in some cases with inference #343

jmesserly opened this issue Sep 22, 2015 · 2 comments

Comments

@jmesserly
Copy link
Contributor

I'm running this on the YAML package.

dartanalyzer --strong issues the following warning, which is an error in DDC:

[warning] The getter 'name' is not defined for the class 'Token' (yaml/lib/src/parser.dart, line 257, col 47)

In this code:

  Event _parseNode({bool block: false, bool indentlessSequence: false}) {
    var token = _scanner.peek();

    if (token is AliasToken) {
      _scanner.scan();
      _state = _states.removeLast();
      return new AliasEvent(token.span, token.name); // <-- WARNING IS HERE
    }

Where _scanner.peek() returns a Token and AliasToken is defined as:

class AliasToken implements Token {
  get type => TokenType.ALIAS;
  final FileSpan span;

  /// The name of the anchor.
  final String name;

  AliasToken(this.span, this.name);

  String toString() => "ALIAS $name";
}

It looks like dynamic token = promotes to AliasToken but Token token = does not, even in existing analyzer. Not sure why, AliasToken should be a subtype of Token... @vsmenon @leafpetersen thoughts?

@jmesserly
Copy link
Contributor Author

Sigh, I guess this is "not a bug" because of some mutation-in-closure that happens later in the method. And at least as currently spec'd type promotion is not smart enough to know that the closure it's afraid of doesn't even exist yet... Sigh.

@jmesserly
Copy link
Contributor Author

I rolled this into #274

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

No branches or pull requests

1 participant