Skip to content
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

Source location for StringConcatenation node for interpolation points to the end of the string. #55690

Open
nshahan opened this issue May 10, 2024 · 2 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-encodings Encoding related CFE issues.

Comments

@nshahan
Copy link
Contributor

nshahan commented May 10, 2024

In the kernel AST for the following code the location for the StringConcatenation node is pointing to the column where the carrot is pointing.

String foo() => 'hello';
String bar() => 'world';

void main() {
  var s = '${foo()} ${bar()}';
  //                        ^
  print(s);
}

I noticed this when working on some problems with source mapped locations in JavaScript output from DDC. I'm working around it for now but most other nodes have a location that point to the beginning of their corresponding source code. Would it make sense if StringConcatenation did too?

cc @johnniwinther

@nshahan nshahan added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label May 10, 2024
@johnniwinther johnniwinther added the cfe-encodings Encoding related CFE issues. label May 13, 2024
@johnniwinther
Copy link
Member

I think it makes more sense to point to the start of the string literal. @jensjoha do you see a problem in making such a change?

@jensjoha
Copy link
Contributor

A StringConcatenation is created via createStringConcatenation which is called twice:

  • push(forest.createStringConcatenation(offsetForToken(endToken), expressions));
  • push(forest.createStringConcatenation(offsetForToken(startToken), expressions ?? parts));

So it's only somtimes it's the end token. Generally I think we just give it what we have available, but yeah, making it the start instead would make more sense.
I'll add it to my todo list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-encodings Encoding related CFE issues.
Projects
None yet
Development

No branches or pull requests

3 participants