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

Configurable imports with prefixes doesn't work as expected #55899

Open
matanlurey opened this issue Jun 1, 2024 · 2 comments
Open

Configurable imports with prefixes doesn't work as expected #55899

matanlurey opened this issue Jun 1, 2024 · 2 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-dysfunctionalities Issues for the CFE not behaving as intended front-end-fasta type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@matanlurey
Copy link
Contributor

I was surprised to see that if I do the following:

import 'impl.dart' as impl if (dart.library.io) 'impl_io.dart';

void main() {
  impl.run();
}

I expected this to, in environments where dart:io is available, call the run function in impl_io.dart.

However, it appears that it unconditionally calls impl.dart due to the prefix, and it's not valid to add the same prefix:

// An import directive can only have one prefix ('as' clause).
// Try removing all but one prefix.
import 'impl.dart' as impl if (dart.library.io) 'impl_io.dart' as impl;
@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) front-end-fasta area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Jun 2, 2024
@lrhn
Copy link
Member

lrhn commented Jun 2, 2024

This should just e a compile-time error. The as clause goes after the if clauses.

If you write it as

import 'impl.dart' if (dart.library.io) 'impl_io.dart' as impl;

it should do what you intend.

Grammatically the 'impl.dart' if (dart.library.io) 'impl_io.dart' is a single production <configurableUri> which is either a URI or a URI followed by one or more conditional URIs.

Filing as parser bug, it shouldn't be allowed to parse with an if ... after the prefix.

@userAdityaa
Copy link

userAdityaa commented Jun 2, 2024

Hey, I'm new to contributing to dart. Can you just help with reproducing this error to me ?
As per my knowledge @lrhn is right, and this is just an issue that should be solved by the following code written.

@johnniwinther johnniwinther added the cfe-dysfunctionalities Issues for the CFE not behaving as intended label Jun 3, 2024
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-dysfunctionalities Issues for the CFE not behaving as intended front-end-fasta type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants