From 3706959abef409ba0991d5cafeed0f25d8e9e2c4 Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Fri, 23 Jun 2023 16:51:29 +0200 Subject: [PATCH] Fix 23722 - Lambdas are mangled incorrectly when using multiple compilation units, resulting in incorrect code --- compiler/src/dmd/expressionsem.d | 4 ++-- compiler/test/fail_compilation/b19523.d | 2 +- compiler/test/fail_compilation/bug9631.d | 2 +- .../test/fail_compilation/constraints_defs.d | 2 +- .../test/fail_compilation/constraints_tmpl.d | 2 +- compiler/test/fail_compilation/cppvar.d | 2 +- compiler/test/fail_compilation/diag12829.d | 2 +- compiler/test/fail_compilation/diag15411.d | 4 ++-- compiler/test/fail_compilation/diag20268.d | 4 ++-- compiler/test/fail_compilation/diag9831.d | 2 +- compiler/test/fail_compilation/diag_funclit.d | 14 +++++++------- compiler/test/fail_compilation/fail11125.d | 4 ++-- compiler/test/fail_compilation/fail12236.d | 4 ++-- compiler/test/fail_compilation/fail12378.d | 6 +++--- compiler/test/fail_compilation/fail12908.d | 2 +- compiler/test/fail_compilation/fail13120.d | 4 ++-- compiler/test/fail_compilation/fail13424.d | 6 +++--- compiler/test/fail_compilation/fail17969.d | 2 +- compiler/test/fail_compilation/fail39.d | 2 +- compiler/test/fail_compilation/iasm1.d | 2 +- compiler/test/fail_compilation/ice10922.d | 4 ++-- compiler/test/fail_compilation/ice11822.d | 4 ++-- compiler/test/fail_compilation/ice11850.d | 2 +- compiler/test/fail_compilation/ice12235.d | 6 +++--- compiler/test/fail_compilation/ice8309.d | 2 +- compiler/test/fail_compilation/misc1.d | 2 +- compiler/test/fail_compilation/opapplyscope.d | 2 +- compiler/test/fail_compilation/previewin.d | 6 +++--- compiler/test/fail_compilation/retscope.d | 10 +++++----- compiler/test/fail_compilation/test15306.d | 4 ++-- compiler/test/fail_compilation/test16193.d | 2 +- compiler/test/fail_compilation/test17451.d | 2 +- compiler/test/fail_compilation/test19107.d | 2 +- compiler/test/fail_compilation/test19971.d | 2 +- compiler/test/fail_compilation/test20719.d | 2 +- compiler/test/fail_compilation/test21912.d | 8 ++++---- compiler/test/fail_compilation/test23170.d | 2 +- compiler/test/fail_compilation/testInference.d | 2 +- compiler/test/fail_compilation/var_func_attr.d | 2 +- compiler/test/runnable/imports/test23722b.d | 14 ++++++++++++++ compiler/test/runnable/test23722.d | 16 ++++++++++++++++ 41 files changed, 99 insertions(+), 69 deletions(-) create mode 100644 compiler/test/runnable/imports/test23722b.d create mode 100644 compiler/test/runnable/test23722.d diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 07b134793845..a83e992cee6a 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -5548,7 +5548,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor { if (exp.fd.ident == Id.empty) { - const(char)[] s; + string s; if (exp.fd.fes) s = "__foreachbody"; else if (exp.fd.tok == TOK.reserved) @@ -5582,7 +5582,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor symtab = sds.symtab; } assert(symtab); - Identifier id = Identifier.generateId(s, symtab.length() + 1); + Identifier id = Identifier.generateIdWithLoc(s, exp.loc); exp.fd.ident = id; if (exp.td) exp.td.ident = id; diff --git a/compiler/test/fail_compilation/b19523.d b/compiler/test/fail_compilation/b19523.d index d2a05c73dc1a..3b2a5e0f2243 100644 --- a/compiler/test/fail_compilation/b19523.d +++ b/compiler/test/fail_compilation/b19523.d @@ -3,7 +3,7 @@ TEST_OUTPUT: ---- fail_compilation/b19523.d(13): Error: undefined identifier `SomeStruct` fail_compilation/b19523.d(14): Error: function `foo` is not callable using argument types `(_error_)` -fail_compilation/b19523.d(14): cannot pass argument `__lambda2` of type `_error_` to parameter `int delegate() arg` +fail_compilation/b19523.d(14): cannot pass argument `__lambda_L14_C6` of type `_error_` to parameter `int delegate() arg` fail_compilation/b19523.d(19): `b19523.foo(int delegate() arg)` declared here ---- */ diff --git a/compiler/test/fail_compilation/bug9631.d b/compiler/test/fail_compilation/bug9631.d index 13974aa0e9a6..833cc95c0f32 100644 --- a/compiler/test/fail_compilation/bug9631.d +++ b/compiler/test/fail_compilation/bug9631.d @@ -65,7 +65,7 @@ TEST_OUTPUT: fail_compilation/bug9631.d(80): Error: function `f` is not callable using argument types `(int, S)` fail_compilation/bug9631.d(80): cannot pass argument `y` of type `bug9631.tem!().S` to parameter `bug9631.S s` fail_compilation/bug9631.d(79): `bug9631.arg.f(int i, S s)` declared here -fail_compilation/bug9631.d(81): Error: function literal `__lambda4(S s)` is not callable using argument types `(S)` +fail_compilation/bug9631.d(81): Error: function literal `__lambda_L81_C5(S s)` is not callable using argument types `(S)` fail_compilation/bug9631.d(81): cannot pass argument `x` of type `bug9631.S` to parameter `bug9631.tem!().S s` fail_compilation/bug9631.d(87): Error: constructor `bug9631.arg.A.this(S __param_0)` is not callable using argument types `(S)` fail_compilation/bug9631.d(87): cannot pass argument `S(0)` of type `bug9631.tem!().S` to parameter `bug9631.S __param_0` diff --git a/compiler/test/fail_compilation/constraints_defs.d b/compiler/test/fail_compilation/constraints_defs.d index 751520864371..b3a335b4e242 100755 --- a/compiler/test/fail_compilation/constraints_defs.d +++ b/compiler/test/fail_compilation/constraints_defs.d @@ -5,7 +5,7 @@ TEST_OUTPUT: fail_compilation/constraints_defs.d(49): Error: template instance `constraints_defs.main.def!(int, 0, (a) => a)` does not match template declaration `def(T, int i = 5, alias R)()` with `T = int, i = 0, - R = __lambda1` + R = __lambda_L49_C18` must satisfy the following constraint: ` N!T` fail_compilation/constraints_defs.d(50): Error: template instance `imports.constraints.defa!int` does not match template declaration `defa(T, U = int)()` diff --git a/compiler/test/fail_compilation/constraints_tmpl.d b/compiler/test/fail_compilation/constraints_tmpl.d index 06caa52493d2..fee7a3e3e7b1 100755 --- a/compiler/test/fail_compilation/constraints_tmpl.d +++ b/compiler/test/fail_compilation/constraints_tmpl.d @@ -22,7 +22,7 @@ fail_compilation/constraints_tmpl.d(41): Error: template instance `imports.const ` N!T N!U` fail_compilation/constraints_tmpl.d(43): Error: template instance `constraints_tmpl.main.lambda!((a) => a)` does not match template declaration `lambda(alias pred)()` - with `pred = __lambda1` + with `pred = __lambda_L43_C13` must satisfy the following constraint: ` N!int` --- diff --git a/compiler/test/fail_compilation/cppvar.d b/compiler/test/fail_compilation/cppvar.d index 885a55547c9b..213b54d10f56 100644 --- a/compiler/test/fail_compilation/cppvar.d +++ b/compiler/test/fail_compilation/cppvar.d @@ -9,7 +9,7 @@ fail_compilation/cppvar.d(21): Error: variable `cppvar.staticVar` cannot have `e fail_compilation/cppvar.d(21): perhaps declare it as `__gshared` instead fail_compilation/cppvar.d(22): Error: variable `cppvar.sharedVar` cannot have `extern(C++)` linkage because it is `shared` fail_compilation/cppvar.d(22): perhaps declare it as `__gshared` instead -fail_compilation/cppvar.d(30): Error: delegate `cppvar.__lambda7` cannot return type `bool[3]` because its linkage is `extern(C++)` +fail_compilation/cppvar.d(30): Error: delegate `cppvar.__lambda_L30_C46` cannot return type `bool[3]` because its linkage is `extern(C++)` --- */ #line 10 diff --git a/compiler/test/fail_compilation/diag12829.d b/compiler/test/fail_compilation/diag12829.d index aaedd0f72175..0ed04d3a7495 100644 --- a/compiler/test/fail_compilation/diag12829.d +++ b/compiler/test/fail_compilation/diag12829.d @@ -2,7 +2,7 @@ TEST_OUTPUT: --- fail_compilation/diag12829.d(15): Error: function `diag12829.test1` is `@nogc` yet allocates closure for `test1()` with the GC -fail_compilation/diag12829.d(18): delegate `diag12829.test1.__lambda2` closes over variable `x` +fail_compilation/diag12829.d(18): delegate `diag12829.test1.__lambda_L18_C33` closes over variable `x` fail_compilation/diag12829.d(17): `x` declared here fail_compilation/diag12829.d(22): function `diag12829.test1.bar` closes over variable `x` fail_compilation/diag12829.d(17): `x` declared here diff --git a/compiler/test/fail_compilation/diag15411.d b/compiler/test/fail_compilation/diag15411.d index 8b18c19d0276..51060b8ffc15 100644 --- a/compiler/test/fail_compilation/diag15411.d +++ b/compiler/test/fail_compilation/diag15411.d @@ -2,9 +2,9 @@ /* TEST_OUTPUT: --- -fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral2` cannot access variable `i` in frame of function `diag15411.test15411` +fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral_L17_C15` cannot access variable `i` in frame of function `diag15411.test15411` fail_compilation/diag15411.d(16): `i` declared here -fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral4` cannot access variable `i` in frame of function `diag15411.test15411` +fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral_L18_C15` cannot access variable `i` in frame of function `diag15411.test15411` fail_compilation/diag15411.d(16): `i` declared here fail_compilation/diag15411.d(26): Error: `static` function `diag15411.testNestedFunction.myFunc2` cannot access function `myFunc1` in frame of function `diag15411.testNestedFunction` fail_compilation/diag15411.d(25): `myFunc1` declared here diff --git a/compiler/test/fail_compilation/diag20268.d b/compiler/test/fail_compilation/diag20268.d index 065349026700..5504aad0c783 100644 --- a/compiler/test/fail_compilation/diag20268.d +++ b/compiler/test/fail_compilation/diag20268.d @@ -3,8 +3,8 @@ /* TEST_OUTPUT: --- -fail_compilation/diag20268.d(12): Error: template `__lambda4` is not callable using argument types `!()(int)` -fail_compilation/diag20268.d(11): Candidate is: `__lambda4(__T1, __T2)(x, y)` +fail_compilation/diag20268.d(12): Error: template `__lambda_L11_C1` is not callable using argument types `!()(int)` +fail_compilation/diag20268.d(11): Candidate is: `__lambda_L11_C1(__T1, __T2)(x, y)` --- */ diff --git a/compiler/test/fail_compilation/diag9831.d b/compiler/test/fail_compilation/diag9831.d index c93a06a465ac..13995d4b6ad1 100644 --- a/compiler/test/fail_compilation/diag9831.d +++ b/compiler/test/fail_compilation/diag9831.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda3(__T1)(x)` cannot access variable `c` in frame of function `D main` +fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda_L13_C12(__T1)(x)` cannot access variable `c` in frame of function `D main` fail_compilation/diag9831.d(11): `c` declared here --- */ diff --git a/compiler/test/fail_compilation/diag_funclit.d b/compiler/test/fail_compilation/diag_funclit.d index f00f91a1fc81..0173d4b78eff 100644 --- a/compiler/test/fail_compilation/diag_funclit.d +++ b/compiler/test/fail_compilation/diag_funclit.d @@ -1,19 +1,19 @@ /** TEST_OUTPUT: --- -fail_compilation/diag_funclit.d(103): Error: function literal `__lambda1(x, y, z)` is not callable using argument types `()` +fail_compilation/diag_funclit.d(103): Error: function literal `__lambda_L103_C5(x, y, z)` is not callable using argument types `()` fail_compilation/diag_funclit.d(103): too few arguments, expected 3, got 0 -fail_compilation/diag_funclit.d(106): Error: function literal `__lambda2(x, y, z)` is not callable using argument types `(int, string, int, int)` +fail_compilation/diag_funclit.d(106): Error: function literal `__lambda_L106_C5(x, y, z)` is not callable using argument types `(int, string, int, int)` fail_compilation/diag_funclit.d(106): too many arguments, expected 3, got 4 -fail_compilation/diag_funclit.d(108): Error: function literal `__lambda3(x, y, string z = "Hello")` is not callable using argument types `(int, int, string, string)` +fail_compilation/diag_funclit.d(108): Error: function literal `__lambda_L108_C5(x, y, string z = "Hello")` is not callable using argument types `(int, int, string, string)` fail_compilation/diag_funclit.d(108): too many arguments, expected 3, got 4 -fail_compilation/diag_funclit.d(110): Error: function literal `__lambda4(x, y, string z = "Hello")` is not callable using argument types `(int)` +fail_compilation/diag_funclit.d(110): Error: function literal `__lambda_L110_C5(x, y, string z = "Hello")` is not callable using argument types `(int)` fail_compilation/diag_funclit.d(110): too few arguments, expected 3, got 1 -fail_compilation/diag_funclit.d(112): Error: function literal `__lambda5(x, y, z)` is not callable using argument types `(int)` +fail_compilation/diag_funclit.d(112): Error: function literal `__lambda_L112_C5(x, y, z)` is not callable using argument types `(int)` fail_compilation/diag_funclit.d(112): too few arguments, expected 3, got 1 -fail_compilation/diag_funclit.d(115): Error: function literal `__lambda6(x, y, ...)` is not callable using argument types `(int)` +fail_compilation/diag_funclit.d(115): Error: function literal `__lambda_L115_C5(x, y, ...)` is not callable using argument types `(int)` fail_compilation/diag_funclit.d(115): too few arguments, expected 2, got 1 -fail_compilation/diag_funclit.d(117): Error: function literal `__lambda7(x, y, string z = "Hey", ...)` is not callable using argument types `(int)` +fail_compilation/diag_funclit.d(117): Error: function literal `__lambda_L117_C5(x, y, string z = "Hey", ...)` is not callable using argument types `(int)` fail_compilation/diag_funclit.d(117): too few arguments, expected 3, got 1 --- */ diff --git a/compiler/test/fail_compilation/fail11125.d b/compiler/test/fail_compilation/fail11125.d index 1a682cd197c8..4349755519d1 100644 --- a/compiler/test/fail_compilation/fail11125.d +++ b/compiler/test/fail_compilation/fail11125.d @@ -2,11 +2,11 @@ TEST_OUTPUT: --- fail_compilation/fail11125.d(26): Error: template instance `fail11125.filter!(function (int a) pure nothrow @nogc @safe => a + 1)` does not match template declaration `filter(alias predfun)` - with `predfun = __lambda1` + with `predfun = __lambda_L26_C13` must satisfy the following constraint: ` is(ReturnType!predfun == bool)` fail_compilation/fail11125.d(27): Error: template instance `fail11125.filter!(function (int a) pure nothrow @nogc @safe => a + 1)` does not match template declaration `filter(alias predfun)` - with `predfun = __lambda2` + with `predfun = __lambda_L27_C17` must satisfy the following constraint: ` is(ReturnType!predfun == bool)` --- diff --git a/compiler/test/fail_compilation/fail12236.d b/compiler/test/fail_compilation/fail12236.d index 824f5e48db25..f27cc2a52159 100644 --- a/compiler/test/fail_compilation/fail12236.d +++ b/compiler/test/fail_compilation/fail12236.d @@ -6,8 +6,8 @@ fail_compilation/fail12236.d(16): while evaluating `pragma(msg, f1.mangle fail_compilation/fail12236.d(21): Error: forward reference to inferred return type of function `f2` fail_compilation/fail12236.d(21): while evaluating `pragma(msg, f2(T)(T).mangleof)` fail_compilation/fail12236.d(27): Error: template instance `fail12236.f2!int` error instantiating -fail_compilation/fail12236.d(31): Error: forward reference to inferred return type of function `__lambda1` -fail_compilation/fail12236.d(31): while evaluating `pragma(msg, __lambda1(__T1)(a).mangleof)` +fail_compilation/fail12236.d(31): Error: forward reference to inferred return type of function `__lambda_L29_C5` +fail_compilation/fail12236.d(31): while evaluating `pragma(msg, __lambda_L29_C5(__T1)(a).mangleof)` --- */ diff --git a/compiler/test/fail_compilation/fail12378.d b/compiler/test/fail_compilation/fail12378.d index 77678ebc0fc0..5a0f9e05ab66 100644 --- a/compiler/test/fail_compilation/fail12378.d +++ b/compiler/test/fail_compilation/fail12378.d @@ -5,7 +5,7 @@ fail_compilation/fail12378.d(18): Error: undefined identifier `ANYTHING` fail_compilation/fail12378.d(18): Error: undefined identifier `GOES` fail_compilation/fail12378.d(91): instantiated from here: `MapResultS!((x0) => ANYTHING - GOES, Result)` fail_compilation/fail12378.d(17): instantiated from here: `mapS!(Result)` -fail_compilation/fail12378.d(100): instantiated from here: `__lambda1!int` +fail_compilation/fail12378.d(100): instantiated from here: `__lambda_L16_C19!int` fail_compilation/fail12378.d(91): instantiated from here: `MapResultS!((y0) => iota(2).mapS!((x0) => ANYTHING - GOES), Result)` fail_compilation/fail12378.d(16): instantiated from here: `mapS!(Result)` --- @@ -27,7 +27,7 @@ fail_compilation/fail12378.d(40): Error: undefined identifier `ANYTHING` fail_compilation/fail12378.d(40): Error: undefined identifier `GOES` fail_compilation/fail12378.d(112): instantiated from here: `MapResultC!((x0) => ANYTHING - GOES, Result)` fail_compilation/fail12378.d(39): instantiated from here: `mapC!(Result)` -fail_compilation/fail12378.d(123): instantiated from here: `__lambda1!int` +fail_compilation/fail12378.d(123): instantiated from here: `__lambda_L38_C19!int` fail_compilation/fail12378.d(112): instantiated from here: `MapResultC!((y0) => iota(2).mapC!((x0) => ANYTHING - GOES), Result)` fail_compilation/fail12378.d(38): instantiated from here: `mapC!(Result)` --- @@ -49,7 +49,7 @@ fail_compilation/fail12378.d(64): Error: undefined identifier `ANYTHING` fail_compilation/fail12378.d(64): Error: undefined identifier `GOES` fail_compilation/fail12378.d(135): instantiated from here: `MapResultI!((x0) => ANYTHING - GOES, Result)` fail_compilation/fail12378.d(63): instantiated from here: `mapI!(Result)` -fail_compilation/fail12378.d(143): instantiated from here: `__lambda1!int` +fail_compilation/fail12378.d(143): instantiated from here: `__lambda_L62_C19!int` fail_compilation/fail12378.d(135): instantiated from here: `MapResultI!((y0) => iota(2).mapI!((x0) => ANYTHING - GOES), Result)` fail_compilation/fail12378.d(62): instantiated from here: `mapI!(Result)` --- diff --git a/compiler/test/fail_compilation/fail12908.d b/compiler/test/fail_compilation/fail12908.d index 67ea6cefb227..3cc6306a80bb 100644 --- a/compiler/test/fail_compilation/fail12908.d +++ b/compiler/test/fail_compilation/fail12908.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail12908.d(14): Error: `pure` delegate `fail12908.main.__foreachbody1` cannot call impure function `fail12908.g` +fail_compilation/fail12908.d(14): Error: `pure` delegate `fail12908.main.__foreachbody_L12_C5` cannot call impure function `fail12908.g` --- */ diff --git a/compiler/test/fail_compilation/fail13120.d b/compiler/test/fail_compilation/fail13120.d index 6a1335eebd5b..1d1127c4c305 100644 --- a/compiler/test/fail_compilation/fail13120.d +++ b/compiler/test/fail_compilation/fail13120.d @@ -1,8 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/fail13120.d(13): Error: `pure` delegate `fail13120.g1.__foreachbody2` cannot call impure function `fail13120.f1` -fail_compilation/fail13120.d(13): Error: `@nogc` delegate `fail13120.g1.__foreachbody2` cannot call non-@nogc function `fail13120.f1` +fail_compilation/fail13120.d(13): Error: `pure` delegate `fail13120.g1.__foreachbody_L12_C5` cannot call impure function `fail13120.f1` +fail_compilation/fail13120.d(13): Error: `@nogc` delegate `fail13120.g1.__foreachbody_L12_C5` cannot call non-@nogc function `fail13120.f1` --- */ void f1() {} diff --git a/compiler/test/fail_compilation/fail13424.d b/compiler/test/fail_compilation/fail13424.d index dcec523a0133..1a7f16b55c55 100644 --- a/compiler/test/fail_compilation/fail13424.d +++ b/compiler/test/fail_compilation/fail13424.d @@ -1,9 +1,9 @@ /* TEST_OUTPUT: --- -fail_compilation/fail13424.d(12): Error: delegate `fail13424.S.__lambda2` cannot be struct members -fail_compilation/fail13424.d(17): Error: delegate `fail13424.U.__lambda2` cannot be union members -fail_compilation/fail13424.d(22): Error: delegate `fail13424.C.__lambda2` cannot be class members +fail_compilation/fail13424.d(12): Error: delegate `fail13424.S.__lambda_L12_C35` cannot be struct members +fail_compilation/fail13424.d(17): Error: delegate `fail13424.U.__lambda_L17_C35` cannot be union members +fail_compilation/fail13424.d(22): Error: delegate `fail13424.C.__lambda_L22_C35` cannot be class members --- */ diff --git a/compiler/test/fail_compilation/fail17969.d b/compiler/test/fail_compilation/fail17969.d index 29bc3f448d83..8272fb0b18c3 100644 --- a/compiler/test/fail_compilation/fail17969.d +++ b/compiler/test/fail_compilation/fail17969.d @@ -1,6 +1,6 @@ /* TEST_OUTPUT: --- -fail_compilation/fail17969.d(10): Error: no property `sum` for type `fail17969.__lambda6!(int[]).__lambda6.MapResult2!((b) => b)` +fail_compilation/fail17969.d(10): Error: no property `sum` for type `fail17969.__lambda_L10_C1!(int[]).__lambda_L10_C1.MapResult2!((b) => b)` fail_compilation/fail17969.d(16): struct `MapResult2` defined here --- * https://issues.dlang.org/show_bug.cgi?id=17969 diff --git a/compiler/test/fail_compilation/fail39.d b/compiler/test/fail_compilation/fail39.d index c0bb0e16a076..f740dda98f16 100644 --- a/compiler/test/fail_compilation/fail39.d +++ b/compiler/test/fail_compilation/fail39.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail39.d(12): Error: function `fail39.main.__funcliteral2` cannot access function `foo` in frame of function `D main` +fail_compilation/fail39.d(12): Error: function `fail39.main.__funcliteral_L12_C27` cannot access function `foo` in frame of function `D main` fail_compilation/fail39.d(11): `foo` declared here --- */ diff --git a/compiler/test/fail_compilation/iasm1.d b/compiler/test/fail_compilation/iasm1.d index 49b01e684412..1fd34b05d31d 100644 --- a/compiler/test/fail_compilation/iasm1.d +++ b/compiler/test/fail_compilation/iasm1.d @@ -116,7 +116,7 @@ void test5() /* TEST_OUTPUT: --- -fail_compilation/iasm1.d(615): Error: delegate `iasm1.test6.__foreachbody1` label `L1` is undefined +fail_compilation/iasm1.d(615): Error: delegate `iasm1.test6.__foreachbody_L611_C5` label `L1` is undefined --- */ diff --git a/compiler/test/fail_compilation/ice10922.d b/compiler/test/fail_compilation/ice10922.d index 552a9824f32e..fc6c593ae0a6 100644 --- a/compiler/test/fail_compilation/ice10922.d +++ b/compiler/test/fail_compilation/ice10922.d @@ -1,9 +1,9 @@ /* TEST_OUTPUT: --- -fail_compilation/ice10922.d(11): Error: function `__lambda4` is not callable using argument types `()` +fail_compilation/ice10922.d(11): Error: function `__lambda_L10_C12` is not callable using argument types `()` fail_compilation/ice10922.d(11): too few arguments, expected 1, got 0 -fail_compilation/ice10922.d(10): `ice10922.__lambda4(in uint n)` declared here +fail_compilation/ice10922.d(10): `ice10922.__lambda_L10_C12(in uint n)` declared here --- */ diff --git a/compiler/test/fail_compilation/ice11822.d b/compiler/test/fail_compilation/ice11822.d index 830af212cb7a..a673a6b2dda6 100644 --- a/compiler/test/fail_compilation/ice11822.d +++ b/compiler/test/fail_compilation/ice11822.d @@ -5,8 +5,8 @@ TEST_OUTPUT: --- fail_compilation/ice11822.d(33): Deprecation: function `ice11822.d` is deprecated -fail_compilation/ice11822.d(16): instantiated from here: `__lambda2!int` -fail_compilation/ice11822.d(22): instantiated from here: `S!(__lambda2)` +fail_compilation/ice11822.d(16): instantiated from here: `__lambda_L33_C15!int` +fail_compilation/ice11822.d(22): instantiated from here: `S!(__lambda_L33_C15)` fail_compilation/ice11822.d(33): instantiated from here: `g!((n) => d(i))` --- */ diff --git a/compiler/test/fail_compilation/ice11850.d b/compiler/test/fail_compilation/ice11850.d index d33549a27f2b..510fe0aae82d 100644 --- a/compiler/test/fail_compilation/ice11850.d +++ b/compiler/test/fail_compilation/ice11850.d @@ -3,7 +3,7 @@ EXTRA_FILES: imports/a11850.d TEST_OUTPUT: --- fail_compilation/ice11850.d(15): Error: incompatible types for `(a) < ([0])`: `uint[]` and `int[]` -fail_compilation/imports/a11850.d(9): instantiated from here: `FilterResult!(__lambda1, uint[][])` +fail_compilation/imports/a11850.d(9): instantiated from here: `FilterResult!(__lambda_L15_C13, uint[][])` fail_compilation/ice11850.d(15): instantiated from here: `filter!(uint[][])` --- */ diff --git a/compiler/test/fail_compilation/ice12235.d b/compiler/test/fail_compilation/ice12235.d index 8f2fefd099ef..ca453e0928d0 100644 --- a/compiler/test/fail_compilation/ice12235.d +++ b/compiler/test/fail_compilation/ice12235.d @@ -1,9 +1,9 @@ /* TEST_OUTPUT: --- -fail_compilation/ice12235.d(14): Error: forward reference to inferred return type of function `__lambda1` -fail_compilation/ice12235.d(15): Error: forward reference to inferred return type of function `__lambda1` -fail_compilation/ice12235.d(15): while evaluating `pragma(msg, __lambda1.mangleof)` +fail_compilation/ice12235.d(14): Error: forward reference to inferred return type of function `__lambda_L12_C5` +fail_compilation/ice12235.d(15): Error: forward reference to inferred return type of function `__lambda_L12_C5` +fail_compilation/ice12235.d(15): while evaluating `pragma(msg, __lambda_L12_C5.mangleof)` --- */ diff --git a/compiler/test/fail_compilation/ice8309.d b/compiler/test/fail_compilation/ice8309.d index 2446914477a1..a9f6f7253acb 100644 --- a/compiler/test/fail_compilation/ice8309.d +++ b/compiler/test/fail_compilation/ice8309.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/ice8309.d(10): Error: incompatible types for `(__lambda1) : (__lambda2)`: `double function() pure nothrow @nogc @safe` and `int function() pure nothrow @nogc @safe` +fail_compilation/ice8309.d(10): Error: incompatible types for `(__lambda_L10_C15) : (__lambda_L10_C24)`: `double function() pure nothrow @nogc @safe` and `int function() pure nothrow @nogc @safe` --- */ diff --git a/compiler/test/fail_compilation/misc1.d b/compiler/test/fail_compilation/misc1.d index 21d02cdae449..2a14f2bcfb42 100644 --- a/compiler/test/fail_compilation/misc1.d +++ b/compiler/test/fail_compilation/misc1.d @@ -4,7 +4,7 @@ TEST_OUTPUT: fail_compilation/misc1.d(108): Error: `5` has no effect fail_compilation/misc1.d(109): Error: `1 + 2` has no effect fail_compilation/misc1.d(115): Deprecation: `1 * 1` has no effect -fail_compilation/misc1.d(116): Deprecation: `__lambda3` has no effect +fail_compilation/misc1.d(116): Deprecation: `__lambda_L116_C34` has no effect fail_compilation/misc1.d(122): Deprecation: `false` has no effect fail_compilation/misc1.d(125): Deprecation: `*sp++` has no effect fail_compilation/misc1.d(126): Deprecation: `j` has no effect diff --git a/compiler/test/fail_compilation/opapplyscope.d b/compiler/test/fail_compilation/opapplyscope.d index 8414bf128454..3eef0f929372 100644 --- a/compiler/test/fail_compilation/opapplyscope.d +++ b/compiler/test/fail_compilation/opapplyscope.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- fail_compilation/opapplyscope.d(113): Error: function `opapplyscope.S.opApply(scope int delegate(scope int* ptr) @safe dg)` is not callable using argument types `(int delegate(int* x) nothrow @nogc @safe)` -fail_compilation/opapplyscope.d(113): cannot pass argument `__foreachbody3` of type `int delegate(int* x) nothrow @nogc @safe` to parameter `scope int delegate(scope int* ptr) @safe dg` +fail_compilation/opapplyscope.d(113): cannot pass argument `__foreachbody_L113_C5` of type `int delegate(int* x) nothrow @nogc @safe` to parameter `scope int delegate(scope int* ptr) @safe dg` --- */ diff --git a/compiler/test/fail_compilation/previewin.d b/compiler/test/fail_compilation/previewin.d index 486dcd5244d2..c3d11cbfd0b9 100644 --- a/compiler/test/fail_compilation/previewin.d +++ b/compiler/test/fail_compilation/previewin.d @@ -3,13 +3,13 @@ REQUIRED_ARGS: -preview=in -preview=dip1000 TEST_OUTPUT: ---- fail_compilation/previewin.d(4): Error: function `takeFunction` is not callable using argument types `(void function(real x) pure nothrow @nogc @safe)` -fail_compilation/previewin.d(4): cannot pass argument `__lambda1` of type `void function(real x) pure nothrow @nogc @safe` to parameter `void function(in real) f` +fail_compilation/previewin.d(4): cannot pass argument `__lambda_L4_C18` of type `void function(real x) pure nothrow @nogc @safe` to parameter `void function(in real) f` fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here fail_compilation/previewin.d(5): Error: function `takeFunction` is not callable using argument types `(void function(scope const(real) x) pure nothrow @nogc @safe)` -fail_compilation/previewin.d(5): cannot pass argument `__lambda2` of type `void function(scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` +fail_compilation/previewin.d(5): cannot pass argument `__lambda_L5_C18` of type `void function(scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here fail_compilation/previewin.d(6): Error: function `takeFunction` is not callable using argument types `(void function(ref scope const(real) x) pure nothrow @nogc @safe)` -fail_compilation/previewin.d(6): cannot pass argument `__lambda3` of type `void function(ref scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` +fail_compilation/previewin.d(6): cannot pass argument `__lambda_L6_C18` of type `void function(ref scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here fail_compilation/previewin.d(15): Error: scope variable `arg` assigned to global variable `myGlobal` fail_compilation/previewin.d(16): Error: scope variable `arg` assigned to global variable `myGlobal` diff --git a/compiler/test/fail_compilation/retscope.d b/compiler/test/fail_compilation/retscope.d index ce983c01fc6f..39a0b4d1c04f 100644 --- a/compiler/test/fail_compilation/retscope.d +++ b/compiler/test/fail_compilation/retscope.d @@ -55,7 +55,7 @@ void test2(scope int* p, int[] a ...) @safe TEST_OUTPUT: --- fail_compilation/retscope.d(75): Error: function `retscope.HTTP.Impl.onReceive` is `@nogc` yet allocates closure for `onReceive()` with the GC -fail_compilation/retscope.d(77): delegate `retscope.HTTP.Impl.onReceive.__lambda1` closes over variable `this` +fail_compilation/retscope.d(77): delegate `retscope.HTTP.Impl.onReceive.__lambda_L77_C23` closes over variable `this` --- */ @@ -234,10 +234,10 @@ void* funretscope(scope dg_t ptr) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` -fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` -fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda4` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` -fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda4` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` +fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda_L248_C21` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` +fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda_L248_C21` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` +fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda_L249_C21` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` +fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda_L249_C21` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() scope @safe` --- */ diff --git a/compiler/test/fail_compilation/test15306.d b/compiler/test/fail_compilation/test15306.d index ff532aea220a..a60e27404215 100644 --- a/compiler/test/fail_compilation/test15306.d +++ b/compiler/test/fail_compilation/test15306.d @@ -1,8 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral2` cannot access mutable data `i` -fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral5` cannot access non-shared data `p` +fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral_L15_C16` cannot access mutable data `i` +fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral_L19_C16` cannot access non-shared data `p` --- */ diff --git a/compiler/test/fail_compilation/test16193.d b/compiler/test/fail_compilation/test16193.d index 39399cf01d80..84dc7d1c6d75 100644 --- a/compiler/test/fail_compilation/test16193.d +++ b/compiler/test/fail_compilation/test16193.d @@ -3,7 +3,7 @@ REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- fail_compilation/test16193.d(39): Error: function `test16193.abc` is `@nogc` yet allocates closure for `abc()` with the GC -fail_compilation/test16193.d(41): delegate `test16193.abc.__foreachbody2` closes over variable `x` +fail_compilation/test16193.d(41): delegate `test16193.abc.__foreachbody_L41_C5` closes over variable `x` fail_compilation/test16193.d(40): `x` declared here --- */ diff --git a/compiler/test/fail_compilation/test17451.d b/compiler/test/fail_compilation/test17451.d index b0cda2105a22..7df77f591f30 100644 --- a/compiler/test/fail_compilation/test17451.d +++ b/compiler/test/fail_compilation/test17451.d @@ -2,7 +2,7 @@ --- fail_compilation/test17451.d(22): Error: undefined identifier `allocator` fail_compilation/test17451.d(23): Error: `false` has no effect -fail_compilation/test17451.d(30): Error: variable `test17451.HashMap!(ThreadSlot).HashMap.__lambda2.v` - size of type `ThreadSlot` is invalid +fail_compilation/test17451.d(30): Error: variable `test17451.HashMap!(ThreadSlot).HashMap.__lambda_L30_C20.v` - size of type `ThreadSlot` is invalid fail_compilation/test17451.d(44): Error: template instance `test17451.HashMap!(ThreadSlot)` error instantiating --- */ diff --git a/compiler/test/fail_compilation/test19107.d b/compiler/test/fail_compilation/test19107.d index 9a6e33586477..8bbfa82717f6 100644 --- a/compiler/test/fail_compilation/test19107.d +++ b/compiler/test/fail_compilation/test19107.d @@ -4,7 +4,7 @@ TEST_OUTPUT: --- fail_compilation/test19107.d(24): Error: template `all` is not callable using argument types `!((c) => c)(string[])` fail_compilation/test19107.d(18): Candidate is: `all(alias pred, T)(T t)` - with `pred = __lambda2, + with `pred = __lambda_L24_C15, T = string[]` must satisfy the following constraint: ` is(typeof(I!pred(t)))` diff --git a/compiler/test/fail_compilation/test19971.d b/compiler/test/fail_compilation/test19971.d index 3d46eeb82ef0..b99afddbdd50 100644 --- a/compiler/test/fail_compilation/test19971.d +++ b/compiler/test/fail_compilation/test19971.d @@ -3,7 +3,7 @@ fail_compilation/test19971.d(16): Error: function `f` is not callable using argument types `(string)` fail_compilation/test19971.d(16): cannot pass argument `"%s"` of type `string` to parameter `int x` fail_compilation/test19971.d(13): `test19971.f(int x)` declared here -fail_compilation/test19971.d(17): Error: function literal `__lambda1(int x)` is not callable using argument types `(string)` +fail_compilation/test19971.d(17): Error: function literal `__lambda_L17_C5(int x)` is not callable using argument types `(string)` fail_compilation/test19971.d(17): cannot pass argument `"%s"` of type `string` to parameter `int x` --- */ diff --git a/compiler/test/fail_compilation/test20719.d b/compiler/test/fail_compilation/test20719.d index b9305f20f80f..4db59d62ae1f 100644 --- a/compiler/test/fail_compilation/test20719.d +++ b/compiler/test/fail_compilation/test20719.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- fail_compilation/test20719.d(13): Error: struct `test20719.SumType` no size because of forward reference -fail_compilation/test20719.d(32): Error: variable `test20719.isCopyable!(SumType).__lambda2.foo` - size of type `SumType` is invalid +fail_compilation/test20719.d(32): Error: variable `test20719.isCopyable!(SumType).__lambda_L32_C22.foo` - size of type `SumType` is invalid fail_compilation/test20719.d(18): Error: template instance `test20719.isCopyable!(SumType)` error instantiating --- */ diff --git a/compiler/test/fail_compilation/test21912.d b/compiler/test/fail_compilation/test21912.d index f8bcb40b5dfb..7e236c8a33a2 100644 --- a/compiler/test/fail_compilation/test21912.d +++ b/compiler/test/fail_compilation/test21912.d @@ -3,16 +3,16 @@ PERMUTE_ARGS: -preview=dip1000 TEST_OUTPUT: --- fail_compilation/test21912.d(28): Error: function `test21912.escapeParam` is `@nogc` yet allocates closure for `escapeParam()` with the GC -fail_compilation/test21912.d(30): delegate `test21912.escapeParam.__lambda2` closes over variable `i` +fail_compilation/test21912.d(30): delegate `test21912.escapeParam.__lambda_L30_C21` closes over variable `i` fail_compilation/test21912.d(28): `i` declared here fail_compilation/test21912.d(33): Error: function `test21912.escapeAssign` is `@nogc` yet allocates closure for `escapeAssign()` with the GC -fail_compilation/test21912.d(35): delegate `test21912.escapeAssign.__lambda3` closes over variable `i` +fail_compilation/test21912.d(35): delegate `test21912.escapeAssign.__lambda_L35_C10` closes over variable `i` fail_compilation/test21912.d(33): `i` declared here fail_compilation/test21912.d(44): Error: function `test21912.escapeAssignRef` is `@nogc` yet allocates closure for `escapeAssignRef()` with the GC -fail_compilation/test21912.d(46): delegate `test21912.escapeAssignRef.__lambda3` closes over variable `i` +fail_compilation/test21912.d(46): delegate `test21912.escapeAssignRef.__lambda_L46_C10` closes over variable `i` fail_compilation/test21912.d(44): `i` declared here fail_compilation/test21912.d(55): Error: function `test21912.escapeParamInferred` is `@nogc` yet allocates closure for `escapeParamInferred()` with the GC -fail_compilation/test21912.d(57): delegate `test21912.escapeParamInferred.__lambda2` closes over variable `i` +fail_compilation/test21912.d(57): delegate `test21912.escapeParamInferred.__lambda_L57_C29` closes over variable `i` fail_compilation/test21912.d(55): `i` declared here --- */ diff --git a/compiler/test/fail_compilation/test23170.d b/compiler/test/fail_compilation/test23170.d index eb79cd81565e..fedf31b5fc83 100644 --- a/compiler/test/fail_compilation/test23170.d +++ b/compiler/test/fail_compilation/test23170.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/test23170.d(10): Error: array literal in `@nogc` delegate `test23170.__lambda5` may cause a GC allocation +fail_compilation/test23170.d(10): Error: array literal in `@nogc` delegate `test23170.__lambda_L10_C15` may cause a GC allocation --- */ // https://issues.dlang.org/show_bug.cgi?id=23170 diff --git a/compiler/test/fail_compilation/testInference.d b/compiler/test/fail_compilation/testInference.d index 145fc9e8b9d6..b3a8a561cf9f 100644 --- a/compiler/test/fail_compilation/testInference.d +++ b/compiler/test/fail_compilation/testInference.d @@ -138,7 +138,7 @@ immutable(void)* g10063(inout int* p) pure TEST_OUTPUT: --- fail_compilation/testInference.d(154): Error: `pure` function `testInference.bar14049` cannot call impure function `testInference.foo14049!int.foo14049` -fail_compilation/testInference.d(149): which calls `testInference.foo14049!int.foo14049.__lambda2` +fail_compilation/testInference.d(149): which calls `testInference.foo14049!int.foo14049.__lambda_L147_C14` fail_compilation/testInference.d(148): which calls `testInference.impure14049` fail_compilation/testInference.d(143): which wasn't inferred `pure` because of: fail_compilation/testInference.d(143): `pure` function `testInference.impure14049` cannot access mutable static data `i` diff --git a/compiler/test/fail_compilation/var_func_attr.d b/compiler/test/fail_compilation/var_func_attr.d index 8609d29b58cb..0753b13f3185 100644 --- a/compiler/test/fail_compilation/var_func_attr.d +++ b/compiler/test/fail_compilation/var_func_attr.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/var_func_attr.d(19): Error: cannot implicitly convert expression `__lambda8` of type `void function() nothrow @nogc @safe` to `void function() pure` +fail_compilation/var_func_attr.d(19): Error: cannot implicitly convert expression `__lambda_L19_C27` of type `void function() nothrow @nogc @safe` to `void function() pure` --- */ diff --git a/compiler/test/runnable/imports/test23722b.d b/compiler/test/runnable/imports/test23722b.d new file mode 100644 index 000000000000..771b875768db --- /dev/null +++ b/compiler/test/runnable/imports/test23722b.d @@ -0,0 +1,14 @@ +struct A { + import core.stdc.stdio; + alias x = () { + printf("x\n"); + }; + alias y = () { + printf("y\n"); + }; +} + +// do_x should call A.x (and print "x") +void do_x() { + A.x(); +} diff --git a/compiler/test/runnable/test23722.d b/compiler/test/runnable/test23722.d new file mode 100644 index 000000000000..0f5b97f4f4a9 --- /dev/null +++ b/compiler/test/runnable/test23722.d @@ -0,0 +1,16 @@ +// COMPILE_SEPARATELY: +// EXTRA_SOURCES: imports/test23722b.d +// REQUIRED_ARGS: -betterC +// https://issues.dlang.org/show_bug.cgi?id=23722 +// Lambdas are mangled incorrectly when using multiple compilation units, resulting in incorrect code +import imports.test23722b; + +// do_y should call A.y (and print "y") +void do_y() { + A.y(); +} + +extern (C) void main() { + do_y(); // should print y + do_x(); // should print x +}