@@ -2364,7 +2364,7 @@ class SymbolIsNotAValue(symbol: Symbol)(using Context) extends TypeMsg(SymbolIsN
2364
2364
}
2365
2365
2366
2366
class DoubleDefinition (decl : Symbol , previousDecl : Symbol , base : Symbol )(using Context )
2367
- extends NamingMsg (DoubleDefinitionID ) {
2367
+ extends NamingMsg (DoubleDefinitionID ):
2368
2368
import Signature .MatchDegree .*
2369
2369
2370
2370
private def erasedType : Type =
@@ -2426,6 +2426,25 @@ extends NamingMsg(DoubleDefinitionID) {
2426
2426
} + details
2427
2427
}
2428
2428
def explain (using Context ) =
2429
+ def givenAddendum =
2430
+ 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(" " )
2441
+ if decl.is(Given ) && previousDecl.is(Given ) && isGivenName(decl) && isGivenName(previousDecl) then
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
+ | """
2447
+ else " "
2429
2448
decl.signature.matchDegree(previousDecl.signature) match
2430
2449
case FullMatch =>
2431
2450
i """
@@ -2439,30 +2458,29 @@ extends NamingMsg(DoubleDefinitionID) {
2439
2458
|
2440
2459
|In your code the two declarations
2441
2460
|
2442
- | ${previousDecl.showDcl}
2443
- | ${decl.showDcl}
2461
+ | ${atPhase(typerPhase)( previousDecl.showDcl) }
2462
+ | ${atPhase(typerPhase)( decl.showDcl) }
2444
2463
|
2445
2464
|erase to the identical signature
2446
2465
|
2447
2466
| ${erasedType}
2448
2467
|
2449
2468
|so the compiler cannot keep both: the generated bytecode symbols would collide.
2450
2469
|
2451
- |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 :
2452
2471
|
2453
- |1. Rename one of the definitions, or
2472
+ |1. Rename one of the definitions. $givenAddendum
2454
2473
|2. Keep the same names in source but give one definition a distinct
2455
- | bytecode-level name via `@targetName` for example:
2474
+ | bytecode-level name via `@targetName`; for example:
2456
2475
|
2457
2476
| @targetName(" ${decl.name.show}_2")
2458
- | ${decl.showDcl}
2477
+ | ${atPhase(typerPhase)( decl.showDcl) }
2459
2478
|
2460
2479
|Choose the `@targetName` argument carefully: it is the name that will be used
2461
2480
|when calling the method externally, so it should be unique and descriptive.
2462
- """
2481
+ | """
2463
2482
case _ => " "
2464
-
2465
- }
2483
+ end DoubleDefinition
2466
2484
2467
2485
class ImportedTwice (sel : Name )(using Context ) extends SyntaxMsg (ImportedTwiceID ) {
2468
2486
def msg (using Context ) = s " ${sel.show} is imported twice on the same import line. "
0 commit comments