@@ -4,7 +4,7 @@ package reporting
4
4
package diagnostic
5
5
6
6
import dotc .core ._
7
- import Contexts .Context , Decorators ._ , Symbols ._ , Names ._ , Types ._
7
+ import Contexts .Context , Decorators ._ , Symbols ._ , Names ._ , NameOps . _ , Types ._
8
8
import ast .untpd .{Modifiers , ModuleDef }
9
9
import util .{SourceFile , NoSource }
10
10
import util .{SourcePosition , NoSourcePosition }
@@ -514,63 +514,74 @@ object messages {
514
514
}
515
515
516
516
case class WrongNumberOfArgs (fntpe : Type , argKind : String , expectedArgs : List [TypeParamInfo ], actual : List [untpd.Tree ])(implicit ctx : Context )
517
- extends Message (18 ) {
517
+ extends Message (19 ) {
518
518
val kind = " Syntax"
519
519
val expectedCount = expectedArgs.length
520
520
val actualCount = actual.length
521
521
val msgPrefix = if (actualCount > expectedCount) " Too many" else " Not enough"
522
522
523
- val expectedArgString = (fntpe.widen match {
524
- case pt : MethodOrPoly => pt // ensure we return a type that will have useful typeParms
525
- case _ => fntpe
526
- }).typeParams.map(_.paramName.show.split(" \\ $" ).last).mkString(" [" , " , " , " ]" )
523
+ val expectedArgString = fntpe.widen.typeParams.map(_.paramName.unexpandedName.show).mkString(" [" , " , " , " ]" )
524
+
525
+ val actualArgString = actual.map(_.show).mkString(" [" , " , " , " ]" )
527
526
528
- val actualArgString = actual.map(_.show.split(" \\ ." ).last).mkString(" [" , " , " , " ]" )
527
+ val prettyName = fntpe.termSymbol match {
528
+ case NoSymbol => fntpe.show
529
+ case symbol => symbol.showFullName
530
+ }
529
531
530
532
val msg =
531
- hl """ | $msgPrefix ${argKind} arguments for $fntpe
533
+ hl """ | ${ NoColor ( msgPrefix)} ${argKind} arguments for $prettyName$expectedArgString
532
534
|expected: $expectedArgString
533
535
|actual: $actualArgString""" .stripMargin
534
536
535
537
val explanation = {
538
+ val tooManyTypeParams =
539
+ """ |val tuple2: (Int, String) = (1, "one")
540
+ |val list: List[(Int, String)] = List(tuple2)""" .stripMargin
541
+
536
542
if (actualCount > expectedCount)
537
543
hl """ |You have supplied too many type parameters
538
544
|
539
545
|For example List takes a single type parameter (List[A])
540
- | If you need to hold more types in a list then you need to combine them
541
- | into another data type that can contain the number of types you need,
542
- | In this example one solution would be to use a Tuple:
543
- | val tuple2: Tuple2[Int, String = (1, "one)
544
- | List[(Int, String)] = List(tuple2) """ .stripMargin
546
+ |If you need to hold more types in a list then you need to combine them
547
+ |into another data type that can contain the number of types you need,
548
+ |In this example one solution would be to use a Tuple:
549
+ |
550
+ | ${tooManyTypeParams} """ .stripMargin
545
551
else
546
552
hl """ |You have not supplied enough type parameters
547
- | If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
553
+ |If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
548
554
}
549
555
}
550
556
551
557
case class IllegalVariableInPatternAlternative ()(implicit ctx : Context )
552
- extends Message (19 ) {
558
+ extends Message (20 ) {
553
559
val kind = " Syntax"
554
560
555
561
val msg = hl """ |Variables are not allowed in alternative patterns """
556
562
557
563
val explanation = {
564
+ val varInAlternative =
565
+ """ |def g(pair: (Int,Int)): Int = pair match {
566
+ | case (1, n) | (n, 1) => n
567
+ | case _ => 0
568
+ |}""" .stripMargin
569
+
570
+ val fixedVarInAlternative =
571
+ """ |def g(pair: (Int,Int)): Int = pair match {
572
+ | case (1, n) => n
573
+ | case (n, 1) => n
574
+ | case _ => 0
575
+ |}""" .stripMargin
576
+
558
577
hl """ |Variables are not allowed within alternate pattern matches.
559
578
|You can workaround this issue by adding additional cases for each alternative.
560
579
|For example, the illegal function:
561
- | def g(pair: (Int,Int)): Int = pair match {
562
- | case (1, n) | (n, 1) => n
563
- | case _ => 0
564
- | }
565
580
|
566
- | could be implemented by moving each alternative into a separate case:
567
- | def g(pair: (Int,Int)): Int = pair match {
568
- | case (1, n) => n
569
- | case (n, 1) => n
570
- | case _ => 0
571
- | }
581
+ | $varInAlternative
582
+ |could be implemented by moving each alternative into a separate case:
572
583
|
573
- | """ .stripMargin
584
+ | $fixedVarInAlternative """ .stripMargin
574
585
}
575
586
}
576
587
}
0 commit comments