@@ -2390,13 +2390,22 @@ extends NamingMsg(DoubleDefinitionID):
23902390 def explain (using Context ) =
23912391 def givenAddendum =
23922392 def isGivenName (sym : Symbol ) = sym.name.startsWith(" given_" ) // Desugar.inventGivenName
2393+ def print (tpe : Type ): String =
2394+ def addParams (tpe : Type ): List [String ] = tpe match
2395+ case tpe : MethodType =>
2396+ val s = if tpe.isContextualMethod then i " ( ${tpe.paramInfos}%, %) => " else " "
2397+ s :: addParams(tpe.resType)
2398+ case tpe : PolyType =>
2399+ i " [ ${tpe.paramNames}%, %] => " :: addParams(tpe.resType)
2400+ case tpe =>
2401+ i " $tpe" :: Nil
2402+ addParams(tpe).mkString(" " )
23932403 if decl.is(Given ) && previousDecl.is(Given ) && isGivenName(decl) && isGivenName(previousDecl) then
2394- i """
2395- |3. Provide an explicit, unique name to given definitions, since the names
2396- | assigned to anonymous givens may clash. For example:
2397- |
2398- | given myGiven: ${atPhase(typerPhase)(decl.info)}
2399- | """
2404+ i """ | Provide an explicit, unique name to given definitions,
2405+ | since the names assigned to anonymous givens may clash. For example:
2406+ |
2407+ | given myGiven: ${print(atPhase(typerPhase)(decl.info))}
2408+ | """
24002409 else " "
24012410 decl.signature.matchDegree(previousDecl.signature) match
24022411 case FullMatch =>
@@ -2420,15 +2429,15 @@ extends NamingMsg(DoubleDefinitionID):
24202429 |
24212430 |so the compiler cannot keep both: the generated bytecode symbols would collide.
24222431 |
2423- |To fix this error, you need to disambiguate the two definitions. You can either :
2432+ |To fix this error, you must disambiguate the two definitions by doing one of the following :
24242433 |
2425- |1. Rename one of the definitions, or
2434+ |1. Rename one of the definitions. $givenAddendum
24262435 |2. Keep the same names in source but give one definition a distinct
24272436 | bytecode-level name via `@targetName`; for example:
24282437 |
24292438 | @targetName(" ${decl.name.show}_2")
24302439 | ${atPhase(typerPhase)(decl.showDcl)}
2431- | $givenAddendum
2440+ |
24322441 |Choose the `@targetName` argument carefully: it is the name that will be used
24332442 |when calling the method externally, so it should be unique and descriptive.
24342443 | """
0 commit comments