Skip to content

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

Merged
merged 4 commits into from
Nov 17, 2016

Conversation

felixmulder
Copy link
Contributor

review: @odersky

@felixmulder
Copy link
Contributor Author

Fixed failing test, this error was not caught previously:

-- Error: tests/neg/i1643.scala --------------------------------------
1 |trait T extends Array {
  |      ^
  |      cannot extend final class Array

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) {
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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
@felixmulder
Copy link
Contributor Author

Done with suggested changes 👍

@odersky
Copy link
Contributor

odersky commented Nov 17, 2016

LGTM, thanks!

@odersky odersky merged commit dd0db48 into scala:master Nov 17, 2016
@allanrenucci allanrenucci deleted the topic/fix#1708 branch December 14, 2017 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants