@@ -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 }
@@ -607,63 +607,75 @@ object messages {
607
607
| """ .stripMargin
608
608
}
609
609
case class WrongNumberOfArgs (fntpe : Type , argKind : String , expectedArgs : List [TypeParamInfo ], actual : List [untpd.Tree ])(implicit ctx : Context )
610
- extends Message (18 ) {
610
+ extends Message (22 ) {
611
611
val kind = " Syntax"
612
612
val expectedCount = expectedArgs.length
613
613
val actualCount = actual.length
614
614
val msgPrefix = if (actualCount > expectedCount) " Too many" else " Not enough"
615
615
616
- val expectedArgString = (fntpe.widen match {
617
- case pt : MethodOrPoly => pt // ensure we return a type that will have useful typeParms
618
- case _ => fntpe
619
- }).typeParams.map(_.paramName.show.split(" \\ $" ).last).mkString(" [" , " , " , " ]" )
616
+ // TODO add def simpleParamName to TypeParamInfo
617
+ val expectedArgString = fntpe.widen.typeParams.map(_.paramName.unexpandedName.show).mkString(" [" , " , " , " ]" )
620
618
621
- val actualArgString = actual.map(_.show.split(" \\ ." ).last).mkString(" [" , " , " , " ]" )
619
+ val actualArgString = actual.map(_.show).mkString(" [" , " , " , " ]" )
620
+
621
+ val prettyName = fntpe.termSymbol match {
622
+ case NoSymbol => fntpe.show
623
+ case symbol => symbol.showFullName
624
+ }
622
625
623
626
val msg =
624
- hl """ | $msgPrefix ${argKind} arguments for $fntpe
627
+ hl """ | ${ NoColor ( msgPrefix)} ${argKind} arguments for $prettyName$expectedArgString
625
628
|expected: $expectedArgString
626
629
|actual: $actualArgString""" .stripMargin
627
630
628
631
val explanation = {
632
+ val tooManyTypeParams =
633
+ """ |val tuple2: (Int, String) = (1, "one")
634
+ |val list: List[(Int, String)] = List(tuple2)""" .stripMargin
635
+
629
636
if (actualCount > expectedCount)
630
637
hl """ |You have supplied too many type parameters
631
638
|
632
639
|For example List takes a single type parameter (List[A])
633
- | If you need to hold more types in a list then you need to combine them
634
- | into another data type that can contain the number of types you need,
635
- | In this example one solution would be to use a Tuple:
636
- | val tuple2: Tuple2[Int, String = (1, "one)
637
- | List[(Int, String)] = List(tuple2) """ .stripMargin
640
+ |If you need to hold more types in a list then you need to combine them
641
+ |into another data type that can contain the number of types you need,
642
+ |In this example one solution would be to use a Tuple:
643
+ |
644
+ | ${tooManyTypeParams} """ .stripMargin
638
645
else
639
646
hl """ |You have not supplied enough type parameters
640
- | If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
647
+ |If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
641
648
}
642
649
}
643
650
644
651
case class IllegalVariableInPatternAlternative ()(implicit ctx : Context )
645
- extends Message (19 ) {
652
+ extends Message (23 ) {
646
653
val kind = " Syntax"
647
654
648
655
val msg = hl """ |Variables are not allowed in alternative patterns """
649
656
650
657
val explanation = {
658
+ val varInAlternative =
659
+ """ |def g(pair: (Int,Int)): Int = pair match {
660
+ | case (1, n) | (n, 1) => n
661
+ | case _ => 0
662
+ |}""" .stripMargin
663
+
664
+ val fixedVarInAlternative =
665
+ """ |def g(pair: (Int,Int)): Int = pair match {
666
+ | case (1, n) => n
667
+ | case (n, 1) => n
668
+ | case _ => 0
669
+ |}""" .stripMargin
670
+
651
671
hl """ |Variables are not allowed within alternate pattern matches.
652
672
|You can workaround this issue by adding additional cases for each alternative.
653
673
|For example, the illegal function:
654
- | def g(pair: (Int,Int)): Int = pair match {
655
- | case (1, n) | (n, 1) => n
656
- | case _ => 0
657
- | }
658
- |
659
- | could be implemented by moving each alternative into a separate case:
660
- | def g(pair: (Int,Int)): Int = pair match {
661
- | case (1, n) => n
662
- | case (n, 1) => n
663
- | case _ => 0
664
- | }
665
674
|
666
- | """ .stripMargin
675
+ | $varInAlternative
676
+ |could be implemented by moving each alternative into a separate case:
677
+ |
678
+ | $fixedVarInAlternative""" .stripMargin
667
679
}
668
680
}
669
681
}
0 commit comments