Skip to content

Commit

Permalink
Merge pull request #9834 from dotty-staging/fix-#9803
Browse files Browse the repository at this point in the history
Fix #9803: Use right context for reporting ambiguous references
  • Loading branch information
odersky committed Sep 22, 2020
2 parents 7830296 + 8264824 commit 61e7370
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Expand Up @@ -188,7 +188,7 @@ class Typer extends Namer
*/
def recurAndCheckNewOrShadowed(previous: Type, prevPrec: BindingPrec, prevCtx: Context)(using Context): Type =
val found = findRefRecur(previous, prevPrec, prevCtx)
if found eq previous then checkNewOrShadowed(found, prevPrec)
if found eq previous then checkNewOrShadowed(found, prevPrec)(using prevCtx)
else found

def selection(imp: ImportInfo, name: Name, checkBounds: Boolean): Type =
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i9803.check
@@ -0,0 +1,8 @@
-- [E049] Reference Error: tests/neg/i9803.scala:15:10 -----------------------------------------------------------------
15 | println(f421()) // error
| ^^^^
| Reference to f421 is ambiguous,
| it is both imported by name by import bugs.shadowing.x.f421
| and imported by name subsequently by import bugs.shadowing.y.f421

longer explanation available when compiling with `-explain`
16 changes: 16 additions & 0 deletions tests/neg/i9803.scala
@@ -0,0 +1,16 @@
package bugs.shadowing

object x {
def f421() = 1
}

object y {
def f421() = true
}

import x.f421
import y.f421

object test {
println(f421()) // error
}

0 comments on commit 61e7370

Please sign in to comment.