Skip to content

Commit c1ace63

Browse files
authored
Fix 23722 - Lambdas are mangled incorrectly when using multiple compi… (dlang/dmd!15343)
* Fix 23722 - Lambdas are mangled incorrectly when using multiple compilation units, resulting in incorrect code * Update test cases
1 parent 35b6470 commit c1ace63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+102
-84
lines changed

dmd/expressionsem.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,7 +5548,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
55485548
{
55495549
if (exp.fd.ident == Id.empty)
55505550
{
5551-
const(char)[] s;
5551+
string s;
55525552
if (exp.fd.fes)
55535553
s = "__foreachbody";
55545554
else if (exp.fd.tok == TOK.reserved)
@@ -5582,7 +5582,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
55825582
symtab = sds.symtab;
55835583
}
55845584
assert(symtab);
5585-
Identifier id = Identifier.generateId(s, symtab.length() + 1);
5585+
Identifier id = Identifier.generateIdWithLoc(s, exp.loc);
55865586
exp.fd.ident = id;
55875587
if (exp.td)
55885588
exp.td.ident = id;

tests/dmd/fail_compilation/b19523.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ TEST_OUTPUT:
33
----
44
fail_compilation/b19523.d(13): Error: undefined identifier `SomeStruct`
55
fail_compilation/b19523.d(14): Error: function `foo` is not callable using argument types `(_error_)`
6-
fail_compilation/b19523.d(14): cannot pass argument `__lambda2` of type `_error_` to parameter `int delegate() arg`
6+
fail_compilation/b19523.d(14): cannot pass argument `__lambda_L14_C6` of type `_error_` to parameter `int delegate() arg`
77
fail_compilation/b19523.d(19): `b19523.foo(int delegate() arg)` declared here
88
----
99
*/

tests/dmd/fail_compilation/bug9631.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST_OUTPUT:
6565
fail_compilation/bug9631.d(80): Error: function `f` is not callable using argument types `(int, S)`
6666
fail_compilation/bug9631.d(80): cannot pass argument `y` of type `bug9631.tem!().S` to parameter `bug9631.S s`
6767
fail_compilation/bug9631.d(79): `bug9631.arg.f(int i, S s)` declared here
68-
fail_compilation/bug9631.d(81): Error: function literal `__lambda4(S s)` is not callable using argument types `(S)`
68+
fail_compilation/bug9631.d(81): Error: function literal `__lambda_L81_C5(S s)` is not callable using argument types `(S)`
6969
fail_compilation/bug9631.d(81): cannot pass argument `x` of type `bug9631.S` to parameter `bug9631.tem!().S s`
7070
fail_compilation/bug9631.d(87): Error: constructor `bug9631.arg.A.this(S __param_0)` is not callable using argument types `(S)`
7171
fail_compilation/bug9631.d(87): cannot pass argument `S(0)` of type `bug9631.tem!().S` to parameter `bug9631.S __param_0`

tests/dmd/fail_compilation/constraints_defs.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TEST_OUTPUT:
55
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)()`
66
with `T = int,
77
i = 0,
8-
R = __lambda1`
8+
R = __lambda_L49_C18`
99
must satisfy the following constraint:
1010
` N!T`
1111
fail_compilation/constraints_defs.d(50): Error: template instance `imports.constraints.defa!int` does not match template declaration `defa(T, U = int)()`

tests/dmd/fail_compilation/constraints_tmpl.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fail_compilation/constraints_tmpl.d(41): Error: template instance `imports.const
2222
` N!T
2323
N!U`
2424
fail_compilation/constraints_tmpl.d(43): Error: template instance `constraints_tmpl.main.lambda!((a) => a)` does not match template declaration `lambda(alias pred)()`
25-
with `pred = __lambda1`
25+
with `pred = __lambda_L43_C13`
2626
must satisfy the following constraint:
2727
` N!int`
2828
---

tests/dmd/fail_compilation/cppvar.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fail_compilation/cppvar.d(21): Error: variable `cppvar.staticVar` cannot have `e
99
fail_compilation/cppvar.d(21): perhaps declare it as `__gshared` instead
1010
fail_compilation/cppvar.d(22): Error: variable `cppvar.sharedVar` cannot have `extern(C++)` linkage because it is `shared`
1111
fail_compilation/cppvar.d(22): perhaps declare it as `__gshared` instead
12-
fail_compilation/cppvar.d(30): Error: delegate `cppvar.__lambda7` cannot return type `bool[3]` because its linkage is `extern(C++)`
12+
fail_compilation/cppvar.d(30): Error: delegate `cppvar.__lambda_L30_C46` cannot return type `bool[3]` because its linkage is `extern(C++)`
1313
---
1414
*/
1515
#line 10

tests/dmd/fail_compilation/diag12829.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TEST_OUTPUT:
33
---
44
fail_compilation/diag12829.d(15): Error: function `diag12829.test1` is `@nogc` yet allocates closure for `test1()` with the GC
5-
fail_compilation/diag12829.d(18): delegate `diag12829.test1.__lambda2` closes over variable `x`
5+
fail_compilation/diag12829.d(18): delegate `diag12829.test1.__lambda_L18_C33` closes over variable `x`
66
fail_compilation/diag12829.d(17): `x` declared here
77
fail_compilation/diag12829.d(22): function `diag12829.test1.bar` closes over variable `x`
88
fail_compilation/diag12829.d(17): `x` declared here

tests/dmd/fail_compilation/diag15411.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/*
33
TEST_OUTPUT:
44
---
5-
fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral2` cannot access variable `i` in frame of function `diag15411.test15411`
5+
fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral_L17_C15` cannot access variable `i` in frame of function `diag15411.test15411`
66
fail_compilation/diag15411.d(16): `i` declared here
7-
fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral4` cannot access variable `i` in frame of function `diag15411.test15411`
7+
fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral_L18_C15` cannot access variable `i` in frame of function `diag15411.test15411`
88
fail_compilation/diag15411.d(16): `i` declared here
99
fail_compilation/diag15411.d(26): Error: `static` function `diag15411.testNestedFunction.myFunc2` cannot access function `myFunc1` in frame of function `diag15411.testNestedFunction`
1010
fail_compilation/diag15411.d(25): `myFunc1` declared here

tests/dmd/fail_compilation/diag20268.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/*
44
TEST_OUTPUT:
55
---
6-
fail_compilation/diag20268.d(12): Error: template `__lambda4` is not callable using argument types `!()(int)`
7-
fail_compilation/diag20268.d(11): Candidate is: `__lambda4(__T1, __T2)(x, y)`
6+
fail_compilation/diag20268.d(12): Error: template `__lambda_L11_C1` is not callable using argument types `!()(int)`
7+
fail_compilation/diag20268.d(11): Candidate is: `__lambda_L11_C1(__T1, __T2)(x, y)`
88
---
99
*/
1010

tests/dmd/fail_compilation/diag9831.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
TEST_OUTPUT:
33
---
4-
fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda3(__T1)(x)` cannot access variable `c` in frame of function `D main`
4+
fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda_L13_C12(__T1)(x)` cannot access variable `c` in frame of function `D main`
55
fail_compilation/diag9831.d(11): `c` declared here
66
---
77
*/

0 commit comments

Comments
 (0)