@@ -2326,7 +2326,7 @@ class JavaSymbolIsNotAValue(symbol: Symbol)(using Context) extends TypeMsg(JavaS
2326
2326
}
2327
2327
2328
2328
class DoubleDefinition (decl : Symbol , previousDecl : Symbol , base : Symbol )(using Context )
2329
- extends NamingMsg (DoubleDefinitionID ) {
2329
+ extends NamingMsg (DoubleDefinitionID ):
2330
2330
import Signature .MatchDegree .*
2331
2331
2332
2332
private def erasedType : Type =
@@ -2388,6 +2388,25 @@ extends NamingMsg(DoubleDefinitionID) {
2388
2388
} + details
2389
2389
}
2390
2390
def explain (using Context ) =
2391
+ def givenAddendum =
2392
+ 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(" " )
2403
+ if decl.is(Given ) && previousDecl.is(Given ) && isGivenName(decl) && isGivenName(previousDecl) then
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
+ | """
2409
+ else " "
2391
2410
decl.signature.matchDegree(previousDecl.signature) match
2392
2411
case FullMatch =>
2393
2412
i """
@@ -2401,30 +2420,29 @@ extends NamingMsg(DoubleDefinitionID) {
2401
2420
|
2402
2421
|In your code the two declarations
2403
2422
|
2404
- | ${previousDecl.showDcl}
2405
- | ${decl.showDcl}
2423
+ | ${atPhase(typerPhase)( previousDecl.showDcl) }
2424
+ | ${atPhase(typerPhase)( decl.showDcl) }
2406
2425
|
2407
2426
|erase to the identical signature
2408
2427
|
2409
2428
| ${erasedType}
2410
2429
|
2411
2430
|so the compiler cannot keep both: the generated bytecode symbols would collide.
2412
2431
|
2413
- |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 :
2414
2433
|
2415
- |1. Rename one of the definitions, or
2434
+ |1. Rename one of the definitions. $givenAddendum
2416
2435
|2. Keep the same names in source but give one definition a distinct
2417
- | bytecode-level name via `@targetName` for example:
2436
+ | bytecode-level name via `@targetName`; for example:
2418
2437
|
2419
2438
| @targetName(" ${decl.name.show}_2")
2420
- | ${decl.showDcl}
2439
+ | ${atPhase(typerPhase)( decl.showDcl) }
2421
2440
|
2422
2441
|Choose the `@targetName` argument carefully: it is the name that will be used
2423
2442
|when calling the method externally, so it should be unique and descriptive.
2424
- """
2443
+ | """
2425
2444
case _ => " "
2426
-
2427
- }
2445
+ end DoubleDefinition
2428
2446
2429
2447
class ImportRenamedTwice (ident : untpd.Ident )(using Context ) extends SyntaxMsg (ImportRenamedTwiceID ) {
2430
2448
def msg (using Context ) = s " ${ident.show} is renamed twice on the same import line. "
0 commit comments