@@ -2428,13 +2428,22 @@ extends NamingMsg(DoubleDefinitionID):
24282428 def explain (using Context ) =
24292429 def givenAddendum =
24302430 def isGivenName (sym : Symbol ) = sym.name.startsWith(" given_" ) // Desugar.inventGivenName
2431+ def print (tpe : Type ): String =
2432+ def addParams (tpe : Type ): List [String ] = tpe match
2433+ case tpe : MethodType =>
2434+ val s = if tpe.isContextualMethod then i " ( ${tpe.paramInfos}%, %) => " else " "
2435+ s :: addParams(tpe.resType)
2436+ case tpe : PolyType =>
2437+ i " [ ${tpe.paramNames}%, %] => " :: addParams(tpe.resType)
2438+ case tpe =>
2439+ i " $tpe" :: Nil
2440+ addParams(tpe).mkString(" " )
24312441 if decl.is(Given ) && previousDecl.is(Given ) && isGivenName(decl) && isGivenName(previousDecl) then
2432- i """
2433- |3. Provide an explicit, unique name to given definitions, since the names
2434- | assigned to anonymous givens may clash. For example:
2435- |
2436- | given myGiven: ${atPhase(typerPhase)(decl.info)}
2437- | """
2442+ i """ | Provide an explicit, unique name to given definitions,
2443+ | since the names assigned to anonymous givens may clash. For example:
2444+ |
2445+ | given myGiven: ${print(atPhase(typerPhase)(decl.info))}
2446+ | """
24382447 else " "
24392448 decl.signature.matchDegree(previousDecl.signature) match
24402449 case FullMatch =>
@@ -2458,15 +2467,15 @@ extends NamingMsg(DoubleDefinitionID):
24582467 |
24592468 |so the compiler cannot keep both: the generated bytecode symbols would collide.
24602469 |
2461- |To fix this error, you need to disambiguate the two definitions. You can either :
2470+ |To fix this error, you must disambiguate the two definitions by doing one of the following :
24622471 |
2463- |1. Rename one of the definitions, or
2472+ |1. Rename one of the definitions. $givenAddendum
24642473 |2. Keep the same names in source but give one definition a distinct
24652474 | bytecode-level name via `@targetName`; for example:
24662475 |
24672476 | @targetName(" ${decl.name.show}_2")
24682477 | ${atPhase(typerPhase)(decl.showDcl)}
2469- | $givenAddendum
2478+ |
24702479 |Choose the `@targetName` argument carefully: it is the name that will be used
24712480 |when calling the method externally, so it should be unique and descriptive.
24722481 | """
0 commit comments