File tree Expand file tree Collapse file tree 3 files changed +43
-4
lines changed
compiler/src/dotty/tools/dotc/reporting Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -2125,8 +2125,27 @@ extends NamingMsg(AlreadyDefinedID):
2125
2125
i " in ${conflicting.associatedFile}"
2126
2126
else if conflicting.owner == owner then " "
2127
2127
else i " in ${conflicting.owner}"
2128
+ def print (tpe : Type ): String =
2129
+ def addParams (tpe : Type ): List [String ] = tpe match
2130
+ case tpe : MethodType =>
2131
+ val s = if tpe.isContextualMethod then i " ( ${tpe.paramInfos}%, %) => " else " "
2132
+ s :: addParams(tpe.resType)
2133
+ case tpe : PolyType =>
2134
+ i " [ ${tpe.paramNames}%, %] => " :: addParams(tpe.resType)
2135
+ case tpe =>
2136
+ i " $tpe" :: Nil
2137
+ addParams(tpe).mkString(" " )
2128
2138
def note =
2129
- if owner.is(Method ) || conflicting.is(Method ) then
2139
+ if conflicting.is(Given ) && name.startsWith(" given_" ) then
2140
+ i """ |
2141
+ |
2142
+ |Provide an explicit, unique name to given definitions,
2143
+ |since the names assigned to anonymous givens may clash. For example:
2144
+ |
2145
+ | given myGiven: ${print(atPhase(typerPhase)(conflicting.info))} // define an instance
2146
+ | given myGiven @ ${print(atPhase(typerPhase)(conflicting.info))} // as a pattern variable
2147
+ | """
2148
+ else if owner.is(Method ) || conflicting.is(Method ) then
2130
2149
" \n\n Note that overloaded methods must all be defined in the same group of toplevel definitions"
2131
2150
else " "
2132
2151
if conflicting.isTerm != name.isTermName then
Original file line number Diff line number Diff line change 1
- -- [E161] Naming Error: tests/neg/i23119.scala:7 :4 ---------------------------------------------------------------------
2
- 7 | given Option[List[Int]] = Some(List(x)) // error
1
+ -- [E161] Naming Error: tests/neg/i23119.scala:8 :4 ---------------------------------------------------------------------
2
+ 8 | given Option[List[Int]] = Some(List(x)) // error
3
3
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4
4
| given_Option_List is already defined as given instance given_Option_List
5
5
|
6
- | Note that overloaded methods must all be defined in the same group of toplevel definitions
6
+ | Provide an explicit, unique name to given definitions,
7
+ | since the names assigned to anonymous givens may clash. For example:
8
+ |
9
+ | given myGiven: Option[List[String]] // define an instance
10
+ | given myGiven @ Option[List[String]] // as a pattern variable
11
+ -- [E161] Naming Error: tests/neg/i23119.scala:18:8 --------------------------------------------------------------------
12
+ 18 | given [A] => List[A] = ??? // error
13
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
14
+ | given_List_A is already defined as given instance given_List_A
15
+ |
16
+ | Provide an explicit, unique name to given definitions,
17
+ | since the names assigned to anonymous givens may clash. For example:
18
+ |
19
+ | given myGiven: [A] => List[A] // define an instance
20
+ | given myGiven @ [A] => List[A] // as a pattern variable
Original file line number Diff line number Diff line change
1
+ //> using options -explain
1
2
2
3
@ main def test = println :
3
4
for x <- 1 to 2
11
12
// given_Option_List is already defined as given instance given_Option_List
12
13
// Previously the naming clash was noticed when extracting values in the map or do function:
13
14
// duplicate pattern variable: given_Option_List
15
+
16
+ def also =
17
+ given [A ] => List [A ] = ???
18
+ given [A ] => List [A ] = ??? // error
19
+ ()
You can’t perform that action at this time.
0 commit comments