@@ -19,7 +19,7 @@ import org.eclipse.lsp4j.CodeAction
1919class DiagnosticProviderSuite extends PcAssertions {
2020 case class TestDiagnostic (startIndex : Int , endIndex : Int , msg : String , severity : DiagnosticSeverity )
2121
22- val pc = RawScalaPresentationCompiler ().newInstance(" " , TestResources .classpath.asJava, Nil .asJava)
22+ val pc = RawScalaPresentationCompiler ().newInstance(" " , TestResources .classpath.asJava, List ( " -explain " ) .asJava)
2323
2424 case class TestVirtualFileParams (uri : URI , text : String ) extends VirtualFileParams {
2525 override def shouldReturnDiagnostics : Boolean = true
@@ -45,6 +45,47 @@ class DiagnosticProviderSuite extends PcAssertions {
4545 | Int.maaxValue
4646 |""" .stripMargin,
4747 List (TestDiagnostic (12 ,25 , " value maaxValue is not a member of object Int - did you mean Int.MaxValue?" , DiagnosticSeverity .Error ))
48+ )
49+
50+ @ Test def error1 =
51+ check(
52+ """ |object C:
53+ | def m(x: Int) = 1
54+ | object T extends K:
55+ | val x = m(1) // error
56+ |class K:
57+ | def m(i: Int) = 2
58+ |""" .stripMargin,
59+ List (
60+ TestDiagnostic (
61+ 64 ,65 ,
62+ """ |Reference to m is ambiguous.
63+ |It is both defined in object C
64+ |and inherited subsequently in object T
65+ |
66+ |# Explanation (enabled by `-explain`)
67+ |
68+ |The identifier m is ambiguous because a name binding of lower precedence
69+ |in an inner scope cannot shadow a binding with higher precedence in
70+ |an outer scope.
71+ |
72+ |The precedence of the different kinds of name bindings, from highest to lowest, is:
73+ | - Definitions in an enclosing scope
74+ | - Inherited definitions and top-level definitions in packages
75+ | - Names introduced by import of a specific name
76+ | - Names introduced by wildcard import
77+ | - Definitions from packages in other files
78+ |Note:
79+ | - As a rule, definitions take precedence over imports.
80+ | - Definitions in an enclosing scope take precedence over inherited definitions,
81+ | which can result in ambiguities in nested classes.
82+ | - When importing, you can avoid naming conflicts by renaming:
83+ | import scala.{m => mTick}
84+ |""" .stripMargin,
85+ DiagnosticSeverity .Error
86+
87+ )
88+ )
4889 )
4990
5091 @ Test def warning =
0 commit comments