Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ Dsymbol search_correct(Scope* _this, Identifier ident)
// https://github.com/dlang/dmd/issues/18763
if (decl.isAliasDeclaration() && decl.inuse)
return null;

// Same reasoning, but for a variable whose own initializer
// is still being resolved. https://github.com/dlang/dmd/issues/20411
if (decl.isVarDeclaration() && sc.varDecl == decl)
return null;
}
// Or `deprecated` ones if we're not in a deprecated scope
if (s.isDeprecated() && !sc.isDeprecated())
Expand Down Expand Up @@ -2410,7 +2415,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
return;
}
//printf("inferring type for %s with init %s\n", dsym.toChars(), dsym._init.toChars());
sc = sc.push();
sc.varDecl = dsym; // https://github.com/dlang/dmd/issues/20411
dsym._init = dsym._init.inferInitializerType(sc, dsym.type, global.errorSink);
sc = sc.pop();
dsym.type = dsym._init.initializerToExpression(null, sc.inCfile).type;

if (autoDollarDims.length)
Expand Down
9 changes: 9 additions & 0 deletions compiler/test/fail_compilation/fix20411.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/fix20411.d(9): Error: undefined identifier `AlmostSimilar`
---
*/

// https://github.com/dlang/dmd/issues/20411
const almostSimilar = AlmostSimilar;
Loading