Skip to content

Commit 599c1b3

Browse files
ibuclawdlang-bot
authored andcommitted
fix Issue 21614 - AssertError@src/dmd/semantic3.d(812): Assertion failure
Template instances may import modules that have not finished semantic1, and in the case of cyclic imports, semantic2 could be ran on a function symbol before semantic1 has begun, which can lead to auto functions given the wrong return type.
1 parent 5ae36c3 commit 599c1b3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/dmd/semantic2.d

+10
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ private extern(C++) final class Semantic2Visitor : Visitor
352352
{
353353
if (fd.semanticRun >= PASS.semantic2done)
354354
return;
355+
356+
if (fd.semanticRun < PASS.semanticdone && !fd.errors)
357+
{
358+
/* https://issues.dlang.org/show_bug.cgi?id=21614
359+
*
360+
* Template instances may import modules that have not
361+
* finished semantic1.
362+
*/
363+
fd.dsymbolSemantic(sc);
364+
}
355365
assert(fd.semanticRun <= PASS.semantic2);
356366
fd.semanticRun = PASS.semantic2;
357367

test/compilable/imports/issue21614a.d

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module imports.issue21614a;
2+
3+
struct FormatSpec(Char)
4+
{
5+
import imports.issue21614a;
6+
}
7+
8+
template Tuple(Specs...)
9+
{
10+
struct Tuple
11+
{
12+
alias spec = FormatSpec!char();
13+
this(Specs)
14+
{
15+
}
16+
}
17+
}
18+
19+
auto findRoot(T)(T)
20+
{
21+
return Tuple!(T)();
22+
}

test/compilable/issue21614.d

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// EXTRA_FILES: imports/issue21614a.d
2+
// REQUIRED_ARGS: -i
3+
4+
// https://issues.dlang.org/show_bug.cgi?id=21614
5+
6+
void logmdigammaInverse(real y)
7+
{
8+
import imports.issue21614a;
9+
findRoot(y);
10+
}

0 commit comments

Comments
 (0)