8000 Analyzer gets confused by string interpolation of `this` · Issue #28206 · dart-lang/sdk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Analyzer gets confused by string interpolation of this #28206

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
Hixie opened this issue Dec 27, 2016 · 5 comments
Closed

Analyzer gets confused by string interpolation of this #28206

Hixie opened this issue Dec 27, 2016 · 5 comments
Labels
area-language Dart language re 8000 lated items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@Hixie
Copy link
Contributor
Hixie commented Dec 27, 2016

The analyzer doesn't like '$this$foo':

class A {
  String test1(String foo) => '$this'; // fine                                                                                                                                                                                 
  String test3(String foo) => '${this}$foo'; // fine                                                                                                                                                                           
  String test2(String foo) => '$this$foo'; // "Undefined name 'this'"                                                                                                                                                          
}

void main() { }

The VM compiler handles all three fine.

@mit-mit mit-mit added the legacy-area-analyzer Use area-devexp instead. label Dec 28, 2016
@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 2, 2017
@lrhn
Copy link
Member
lrhn commented Jan 6, 2017

Behavior is correct. You can only use an identifier after a $ in an interpolated string and this is a reserved word, not an identifier.

(Not saying it's not annoying, and we shouldn't consider allowing it, but currently the analyzer is correct, and dart2js also rejects the program, although with a not very useful error message).

@bwilkerson bwilkerson added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed legacy-area-analyzer Use area-devexp 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) labels Jan 6, 2017
@Hixie
Copy link
Contributor Author
Hixie commented Jan 6, 2017

Well ok, but the analyzer disagrees with the VM and the VM is more convenient in this case so I suggest we just change the analyzer (and if necessary, the spec). :-)

@lrhn
Copy link
Member
lrhn commented Jan 7, 2017

I'll mark this as a language change request then. One that I'm quite positive to :)

@lrhn lrhn added the type-enhancement A request for a change that isn't a bug label Jan 7, 2017
@srawlins
Copy link
Member

Behavior is correct. You can only use an identifier after a $ in an interpolated string and this is a reserved word, not an identifier.

Then why is String test1(String foo) => '$this'; allowed? Still seems like an analyzer inconsistency with the spec. CFE seems fine with '$this' as well...

@lrhn lrhn added the closed-stale Closed as the issue or PR is assumed stale label Apr 9, 2025
@lrhn lrhn closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2025
@eernstg eernstg removed the closed-stale Closed as the issue or PR is assumed stale label Apr 10, 2025
@eernstg
Copy link
Member
eernstg commented Apr 10, 2025

Today, no error is reported for the example in the original posting.

@eernstg eernstg reopened this Apr 10, 2025
@eernstg eernstg closed this as completed Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants
0