-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1708: duplicate symbols in package #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixed failing test, this error was not caught previously:
|
else { | ||
/** If there's already an existing type, then the package is a dup of this type */ | ||
val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName) | ||
if (existingTpe != NoSymbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More idiomatic: if (existingType.exists)
val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName) | ||
if (existingTpe != NoSymbol) { | ||
ctx.error(PkgDuplicateSymbol(existingTpe), pid.pos) | ||
ctx.newCompletePackageSymbol(pkgOwner, (pid.name ++ "$termDup").toTermName).entered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose we use the naming scheme pid.name ++ "$_error_
here.
@@ -261,10 +262,10 @@ class Namer { typer: Typer => | |||
ctx.error(msg, tree.pos) | |||
name.freshened | |||
} | |||
def preExisting = ctx.effectiveScope.lookup(name) | |||
lazy val preExisting = ctx.effectiveScope.lookup(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a lazy val here. preExisting is only used once on each path. Note that defs are more compact (in terms of byte code length) and efficient than lazy vals.
Here we unlink the existing type that clashes with the package to be entered into the symbol table, issue an error and the proceed to enter the rest of the symbols. My concern with this approach is what happens during typechecking if other things reference the unlinked type.
Unlinking proved to cause other problems in the typer, specifically if typechecking members of non-existing package or things referring to the unlinked package
be0adfd
to
040379e
Compare
Done with suggested changes 👍 |
LGTM, thanks! |
review: @odersky