-
-
Notifications
You must be signed in to change notification settings - Fork 613
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
Ambiguous type deduction around file imports (frontend 2.110) #20635
Comments
cc @Geod24 |
Regression was brought to the surface by #16638, possibly caused by #16263. #16638 caused string imports to be treated as hex strings. Note that they suffer from the same issue: void fn(in ubyte[] value){}
void fn(in string value){}
void main() {
// Error: `app.fn` called with argument types `(ubyte[])` matches both:
// `app.fn(in ubyte[] value)`
// and:
// `app.fn(in string value)`
fn(cast(ubyte[])x"AA BB CC DD");
// Ok
fn(cast(immutable ubyte[])[]);
// Ok
string valuestr = "hello world";
fn(cast(ubyte[])valuestr);
} While I haven't done the bisection to confirm it, this version of the code regressed with DMD 2.108.0, which happened to include #16263, which dramatically changed how these work. ping @dkorpel |
There's a lot going on. First of all, immutable data is being cast to a mutable Then, without -preview=in, the two overloads are equivalent to: void fn(const ubyte[] value){}
void fn(const string value){} Because the cast is to The second function used to be 'no match', because the
Compile-time known integer arrays do convert to strings, even after explicitly casting: string x = [1, 2, 3];
string y = cast(short[]) [4, 5, 6]; So now both overloads match with implicit conversions, so you get an ambiguity error. I'm not sure why the first overload doesn't match with 'qualifier conversion' (which has priority over 'implicit conversion'), but I'll look into it. Also I hate how In terms of solutions, I'm thinking:
|
FYI the original code had |
It turns out a bug made the match level of qualifier conversion get overridden by implicit conversion. Fixed by #20679, I added a test for both the mutable and immutable cast. |
When importing a file as data, the type get ambiguously detected and leads to strange type errors, hinting that a
ubyte[]
could get implicitly converted tostring
.This bug appeared on both LDC
1.40.0
and DMD2.110.0-beta.1
, and seems to be related with the frontend version 2110.LDC
1.39.0
and DMDv2.109.1
are fine.This issue was originally opened on LDC: ldc-developers/ldc#4813
Reproduction
"stringImportPaths": ["."]
dub run
The full output is:
I couldn't reproduce the issue without the import. Importing a text or a binary file gives the same error.
The text was updated successfully, but these errors were encountered: