@@ -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,75 @@ 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 (22 ) {
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
+ // TODO add def simpleParamName to TypeParamInfo
524
+ val expectedArgString = fntpe.widen.typeParams.map(_.paramName.unexpandedName.show).mkString(" [" , " , " , " ]" )
527
525
528
- val actualArgString = actual.map(_.show.split(" \\ ." ).last).mkString(" [" , " , " , " ]" )
526
+ val actualArgString = actual.map(_.show).mkString(" [" , " , " , " ]" )
527
+
528
+ val prettyName = fntpe.termSymbol match {
529
+ case NoSymbol => fntpe.show
530
+ case symbol => symbol.showFullName
531
+ }
529
532
530
533
val msg =
531
- hl """ | $msgPrefix ${argKind} arguments for $fntpe
534
+ hl """ | ${ NoColor ( msgPrefix)} ${argKind} arguments for $prettyName$expectedArgString
532
535
|expected: $expectedArgString
533
536
|actual: $actualArgString""" .stripMargin
534
537
535
538
val explanation = {
539
+ val tooManyTypeParams =
540
+ """ |val tuple2: (Int, String) = (1, "one")
541
+ |val list: List[(Int, String)] = List(tuple2)""" .stripMargin
542
+
536
543
if (actualCount > expectedCount)
537
544
hl """ |You have supplied too many type parameters
538
545
|
539
546
|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
547
+ |If you need to hold more types in a list then you need to combine them
548
+ |into another data type that can contain the number of types you need,
549
+ |In this example one solution would be to use a Tuple:
550
+ |
551
+ | ${tooManyTypeParams} """ .stripMargin
545
552
else
546
553
hl """ |You have not supplied enough type parameters
547
- | If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
554
+ |If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
548
555
}
549
556
}
550
557
551
558
case class IllegalVariableInPatternAlternative ()(implicit ctx : Context )
552
- extends Message (19 ) {
559
+ extends Message (23 ) {
553
560
val kind = " Syntax"
554
561
555
562
val msg = hl """ |Variables are not allowed in alternative patterns """
556
563
557
564
val explanation = {
565
+ val varInAlternative =
566
+ """ |def g(pair: (Int,Int)): Int = pair match {
567
+ | case (1, n) | (n, 1) => n
568
+ | case _ => 0
569
+ |}""" .stripMargin
570
+
571
+ val fixedVarInAlternative =
572
+ """ |def g(pair: (Int,Int)): Int = pair match {
573
+ | case (1, n) => n
574
+ | case (n, 1) => n
575
+ | case _ => 0
576
+ |}""" .stripMargin
577
+
558
578
hl """ |Variables are not allowed within alternate pattern matches.
559
579
|You can workaround this issue by adding additional cases for each alternative.
560
580
|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
581
|
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
- | }
582
+ | $varInAlternative
583
+ |could be implemented by moving each alternative into a separate case:
572
584
|
573
- | """ .stripMargin
585
+ | $fixedVarInAlternative """ .stripMargin
574
586
}
575
587
}
576
588
}
0 commit comments