Skip to content

Commit

Permalink
[dsymbolsem.d] use early continue
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator committed Nov 25, 2024
1 parent 8e83403 commit 5f06d60
Showing 1 changed file with 81 additions and 82 deletions.
163 changes: 81 additions & 82 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6071,99 +6071,98 @@ private extern(C++) class SearchVisitor : Visitor
if (s && s.isOverloadSet())
a = sds.mergeOverloadSet(ident, a, s);
}
else if (s2 && s != s2)
{
if (s.toAlias() == s2.toAlias() || s.getType() == s2.getType() && s.getType())
{
/* After following aliases, we found the same
* symbol, so it's not an ambiguity. But if one
* alias is deprecated or less accessible, prefer
* the other.
*/
if (s.isDeprecated() || s.visible() < s2.visible() && s2.visible().kind != Visibility.Kind.none)
s = s2;
}
else
{
/* Two imports of the same module should be regarded as
* the same.
*/
Import i1 = s.isImport();
Import i2 = s2.isImport();
if (!(i1 && i2 && (i1.mod == i2.mod || (!i1.parent.isImport() && !i2.parent.isImport() && i1.ident.equals(i2.ident)))))
{
/* https://issues.dlang.org/show_bug.cgi?id=8668
* Public selective import adds AliasDeclaration in module.
* To make an overload set, resolve aliases in here and
* get actual overload roots which accessible via s and s2.
*/
s = s.toAlias();
s2 = s2.toAlias();
/* If both s2 and s are overloadable (though we only
* need to check s once)
*/
else if (!s2 || s == s2)
continue;

auto so2 = s2.isOverloadSet();
if ((so2 || s2.isOverloadable()) && (a || s.isOverloadable()))
{
if (symbolIsVisible(sds, s2))
{
a = sds.mergeOverloadSet(ident, a, s2);
}
if (!symbolIsVisible(sds, s))
s = s2;
continue;
}
if (s.toAlias() == s2.toAlias() || s.getType() == s2.getType() && s.getType())
{
/* After following aliases, we found the same
* symbol, so it's not an ambiguity. But if one
* alias is deprecated or less accessible, prefer
* the other.
*/
if (s.isDeprecated() || s.visible() < s2.visible() && s2.visible().kind != Visibility.Kind.none)
s = s2;
continue;
}

/* Two different overflow sets can have the same members
* https://issues.dlang.org/show_bug.cgi?id=16709
*/
auto so = s.isOverloadSet();
if (so && so2)
{
if (so.a.length == so2.a.length)
{
foreach (j; 0 .. so.a.length)
{
if (so.a[j] !is so2.a[j])
goto L1;
}
continue; // the same
L1:
{ } // different
}
}
/* Two imports of the same module should be regarded as
* the same.
*/
Import i1 = s.isImport();
Import i2 = s2.isImport();
if (i1 && i2 && (i1.mod == i2.mod || (!i1.parent.isImport() && !i2.parent.isImport() && i1.ident.equals(i2.ident))))
continue;

if (flags & SearchOpt.ignoreAmbiguous) // if return NULL on ambiguity
return setResult(null);
/* https://issues.dlang.org/show_bug.cgi?id=8668
* Public selective import adds AliasDeclaration in module.
* To make an overload set, resolve aliases in here and
* get actual overload roots which accessible via s and s2.
*/
s = s.toAlias();
s2 = s2.toAlias();
/* If both s2 and s are overloadable (though we only
* need to check s once)
*/

/* If two imports from C import files, pick first one, as C has global name space
*/
if (s.isCsymbol() && s2.isCsymbol())
continue;
auto so2 = s2.isOverloadSet();
if ((so2 || s2.isOverloadable()) && (a || s.isOverloadable()))
{
if (symbolIsVisible(sds, s2))
{
a = sds.mergeOverloadSet(ident, a, s2);
}
if (!symbolIsVisible(sds, s))
s = s2;
continue;
}

if (!(flags & SearchOpt.ignoreErrors))
ScopeDsymbol.multiplyDefined(loc, s, s2);
break;
/* Two different overflow sets can have the same members
* https://issues.dlang.org/show_bug.cgi?id=16709
*/
auto so = s.isOverloadSet();
if (so && so2)
{
if (so.a.length == so2.a.length)
{
foreach (j; 0 .. so.a.length)
{
if (so.a[j] !is so2.a[j])
goto L1;
}
continue; // the same
L1:
{ } // different
}
}

if (flags & SearchOpt.ignoreAmbiguous) // if return NULL on ambiguity
return setResult(null);

/* If two imports from C import files, pick first one, as C has global name space
*/
if (s.isCsymbol() && s2.isCsymbol())
continue;

if (!(flags & SearchOpt.ignoreErrors))
ScopeDsymbol.multiplyDefined(loc, s, s2);
break;
}
if (s)
if (!s)
{
/* Build special symbol if we had multiple finds
*/
if (a)
{
if (!s.isOverloadSet())
a = sds.mergeOverloadSet(ident, a, s);
s = a;
}
//printf("\tfound in imports %s.%s\n", toChars(), s.toChars());
return setResult(s);
//printf(" not found in imports\n");
return setResult(null);
}
//printf(" not found in imports\n");
return setResult(null);
/* Build special symbol if we had multiple finds
*/
if (a)
{
if (!s.isOverloadSet())
a = sds.mergeOverloadSet(ident, a, s);
s = a;
}
//printf("\tfound in imports %s.%s\n", toChars(), s.toChars());
return setResult(s);
}

override void visit(WithScopeSymbol ws)
Expand Down

0 comments on commit 5f06d60

Please sign in to comment.