Skip to content

Fix #2324: Check contexts in right order when looking for idents #2327

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 3 commits into from
Apr 28, 2017
Merged
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
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
!noImports &&
(prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))

@tailrec def loop(implicit ctx: Context): Type = {
@tailrec def loop(lastCtx: Context)(implicit ctx: Context): Type = {
if (ctx.scope == null) previous
else {
val outer = ctx.outer
var result: Type = NoType

// find definition
if ((ctx.scope ne outer.scope) || (ctx.owner ne outer.owner)) {
if ((lastCtx eq ctx) || (ctx.scope ne lastCtx.scope) || (ctx.owner ne lastCtx.owner)) {
val defDenot = ctx.denotNamed(name)
if (qualifies(defDenot)) {
val curOwner = ctx.owner
Expand All @@ -275,13 +274,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
if (defDenot.symbol is Package)
result = checkNewOrShadowed(previous orElse found, packageClause)
else if (prevPrec < packageClause)
result = findRef(found, packageClause, ctx)(outer)
result = findRef(found, packageClause, ctx)(ctx.outer)
}
}
}

if (result.exists) result
else { // find import
val outer = ctx.outer
val curImport = ctx.importInfo
def updateUnimported() =
if (curImport.unimported.exists) unimported += curImport.unimported
Expand All @@ -297,20 +297,21 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
findRef(checkNewOrShadowed(wildImp, wildImport), wildImport, ctx)(outer)
else {
updateUnimported()
loop(outer)
loop(ctx)(outer)
}
}
else {
updateUnimported()
loop(outer)
loop(ctx)(outer)
}
}
else loop(outer)
else loop(ctx)(outer)
}
}
}

loop
// begin findRef
loop(ctx)(ctx)
}

// begin typedIdent
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i1641.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bar { object bippy extends (Double => String) { def apply(x: Double): St
package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" }
object Test {
def main(args: Array[String]): Unit = {
println(bar.bippy(5.5))
println(bar.bippy(5.5)) // error
println(bar.bippy(1, 2, 3)) // error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be two errors here now? One for the println and one for bippy. That's what happens in scalac.

Copy link
Contributor Author

@odersky odersky Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that's unrelated. Maybe they have the same position in dotty, or we are more aggressive about propagating error types. Anyway we went from 1 to 2 errors, so it's an improvement :-)

}
}
16 changes: 16 additions & 0 deletions tests/pos/i2324.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object A {
def foo: Int = 1
}
object B {
def foo: Int = 2
}
class C {
import A._
import B._

def bar: Int = 4

def foo: Int = 3

println(foo)
}