File tree Expand file tree Collapse file tree 2 files changed +58
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -676,7 +676,7 @@ object Parsers {
676
676
val t = typ()
677
677
findWildcardType(t) match {
678
678
case Some (wildcardPos) =>
679
- syntaxError(" unbound wildcard type " , wildcardPos)
679
+ syntaxError(UnboundWildcardType () , wildcardPos)
680
680
scalaAny
681
681
case None => t
682
682
}
Original file line number Diff line number Diff line change @@ -923,4 +923,61 @@ object messages {
923
923
| """
924
924
}
925
925
926
+ case class UnboundWildcardType ()(implicit ctx : Context ) extends Message (35 ) {
927
+ val kind = " Syntax"
928
+ val msg = " Unbound wildcard type"
929
+ val explanation = {
930
+
931
+ val paramListWildcard = """ def foo(x: _) = ..."""
932
+ val paramList = """ def foo(x: Any) = ..."""
933
+
934
+ val typeArgsWildcard = """ val foo = List[_](1, 2)"""
935
+ val typeArgs = """ val foo = List[Int](1, 2)"""
936
+
937
+ val typeBoundsWildcard = """ def foo[T <: _](x: T) = ..."""
938
+ val typeBounds = """ def foo[T](x: T) = ..."""
939
+
940
+ val valTypeWildcard = """ val foo: _ = 3"""
941
+ val valType = """ val foo: Int = 3"""
942
+
943
+ hl """ |The wildcard type syntax (`_`) was used where it could not be bound.
944
+ |Replace `_` with a non-wildcard type. If the type doesn't matter,
945
+ |try replacing `_` with ${" Any" }.
946
+ |
947
+ |Examples:
948
+ |
949
+ |- Parameter lists
950
+ |
951
+ | Instead of:
952
+ | $paramListWildcard
953
+ |
954
+ | Use ${" Any" } if the type doesn't matter:
955
+ | $paramList
956
+ |
957
+ |- Type arguments
958
+ |
959
+ | Instead of:
960
+ | $typeArgsWildcard
961
+ |
962
+ | Use:
963
+ | $typeArgs
964
+ |
965
+ |- Type bounds
966
+ |
967
+ | Instead of:
968
+ | $typeBoundsWildcard
969
+ |
970
+ | Remove the bounds if the type doesn't matter:
971
+ | $typeBounds
972
+ |
973
+ |- ${" val" } and ${" def" } types
974
+ |
975
+ | Instead of:
976
+ | $valTypeWildcard
977
+ |
978
+ | Use:
979
+ | $valType
980
+ | """
981
+ }
982
+ }
926
983
}
You can’t perform that action at this time.
0 commit comments