Skip to content

[cfe] Instantiated function tearoff does have Object methods #46887

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

Closed
eernstg opened this issue Aug 12, 2021 · 8 comments
Closed

[cfe] Instantiated function tearoff does have Object methods #46887

eernstg opened this issue Aug 12, 2021 · 8 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Aug 12, 2021

[Edit] We do have a rule here which says that a term like a<b, c>.toString() must be parsed as a constructor invocation when a<b, c> is a type literal, not as an instance method invocation on that type literal. But the specification does not explicitly address the case where a<b, c> is a generic function instantiation.

Old text (striking out the part which is currently not resolved, cf. dart-lang/language#1802):

Consider the test co19/LanguageFeatures/Constructor-tear-offs/ambiguities_A08_t02.dart.

In this test there is an expression a<b, c>.toString() where a is a generic function and b and c are types. The parser should parse a<b, c> as <primary><selector> where <selector> further derives <typeArguments>, because the next token is '.' (which is one of those tokens that force the preceding construct to be considered as a <typeArguments>). I believe this part works as it should.

However, that expression should then denote a toString() invocation on a function object that is obtained by explicit generic function instantiation, and there should not be any errors. The CFE reports a compile-time error Method not found.

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. labels Aug 12, 2021
@eernstg
Copy link
Member Author

eernstg commented Aug 12, 2021

The same situation seems to exist in co19/LanguageFeatures/Constructor-tear-offs/ambiguities_A08_t03.dart.

@eernstg
Copy link
Member Author

eernstg commented Aug 12, 2021

Same situation in co19/LanguageFeatures/Constructor-tear-offs/ambiguities_A13_t03.dart.

@eernstg
Copy link
Member Author

eernstg commented Aug 12, 2021

The core question here is currently being resolved at dart-lang/language#1802. Re-opening and marking as blocked.

@stereotype441
Copy link
Member

Was just discussing this bug with @srawlins and realized that if we want a<b, c>.toString() to be allowed (where a refers to a generic function/method), then a<b, c>.call(...) should probably be allowed too.

(@eernstg I think you've been working on test cases for this sort of thing? You might want to add some test cases for .call if you haven't already).

@eernstg
Copy link
Member Author

eernstg commented Aug 25, 2021

Thanks! a<b, c>.call(...) should surely be allowed whenever a has a function type or a.call is a constructor name, I'll include that.

@lrhn
Copy link
Member

lrhn commented Aug 26, 2021

(The analyzer might want to hint that a<b, c>(...) is a shorter version of the same thing, though).

@stereotype441
Copy link
Member

(The analyzer might want to hint that a<b, c>(...) is a shorter version of the same thing, though).

Good point. @pq or @bwilkerson, do you know whether this would be better as a lint or a hint? And would you mind taking ownership of this feature request?

@eernstg
Copy link
Member Author

eernstg commented Aug 26, 2021

dart-lang/language#1802 has been closed: f<int>.toString() is a non-error term that invokes toString() on a function object, and C<int>.toString() is an error unless C.toString is the name of a constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants