Skip to content

Fix #9803: Use right context for reporting ambiguous references #9834

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 1 commit into from
Sep 22, 2020
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}