Skip to content

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

Closed
@eernstg

Description

@eernstg

[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.

Activity

added
type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
on Aug 12, 2021
eernstg

eernstg commented on Aug 12, 2021

@eernstg
MemberAuthor

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

eernstg

eernstg commented on Aug 12, 2021

@eernstg
MemberAuthor

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

added
P2A bug or feature request we're likely to work on
on Aug 12, 2021
eernstg

eernstg commented on Aug 12, 2021

@eernstg
MemberAuthor

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

added
status-blockedBlocked from making progress by another (referenced) issue
on Aug 12, 2021
stereotype441

stereotype441 commented on Aug 23, 2021

@stereotype441
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

eernstg commented on Aug 25, 2021

@eernstg
MemberAuthor

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

lrhn commented on Aug 26, 2021

@lrhn
Member

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

stereotype441

stereotype441 commented on Aug 26, 2021

@stereotype441
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

eernstg commented on Aug 26, 2021

@eernstg
MemberAuthor

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.

removed
status-blockedBlocked from making progress by another (referenced) issue
on Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @stereotype441@chloestefantsova@lrhn@eernstg@johnniwinther

      Issue actions

        [cfe] Instantiated function tearoff does have `Object` methods · Issue #46887 · dart-lang/sdk