Skip to content

Commit 61e7370

Browse files
authored
Merge pull request #9834 from dotty-staging/fix-#9803
Fix #9803: Use right context for reporting ambiguous references
2 parents 7830296 + 8264824 commit 61e7370

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Typer extends Namer
188188
*/
189189
def recurAndCheckNewOrShadowed(previous: Type, prevPrec: BindingPrec, prevCtx: Context)(using Context): Type =
190190
val found = findRefRecur(previous, prevPrec, prevCtx)
191-
if found eq previous then checkNewOrShadowed(found, prevPrec)
191+
if found eq previous then checkNewOrShadowed(found, prevPrec)(using prevCtx)
192192
else found
193193

194194
def selection(imp: ImportInfo, name: Name, checkBounds: Boolean): Type =

tests/neg/i9803.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E049] Reference Error: tests/neg/i9803.scala:15:10 -----------------------------------------------------------------
2+
15 | println(f421()) // error
3+
| ^^^^
4+
| Reference to f421 is ambiguous,
5+
| it is both imported by name by import bugs.shadowing.x.f421
6+
| and imported by name subsequently by import bugs.shadowing.y.f421
7+
8+
longer explanation available when compiling with `-explain`

tests/neg/i9803.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package bugs.shadowing
2+
3+
object x {
4+
def f421() = 1
5+
}
6+
7+
object y {
8+
def f421() = true
9+
}
10+
11+
import x.f421
12+
import y.f421
13+
14+
object test {
15+
println(f421()) // error
16+
}

0 commit comments

Comments
 (0)