File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +44
-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,47 @@ 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
+ hl """ |The wildcard type syntax (`_`) was used where it could not be bound.
931
+ |Replace `_` with a non-wildcard type. If the type doesn't matter,
932
+ |try replacing `_` with ${" Any" }.
933
+ |
934
+ |Examples:
935
+ |
936
+ |- Parameter lists
937
+ |
938
+ | Instead of:
939
+ | ${" def foo(x: _) = ..." }
940
+ |
941
+ | Use ${" Any" } if the type doesn't matter:
942
+ | ${" def foo(x: Any) = ..." }
943
+ |
944
+ |- Type arguments
945
+ |
946
+ | Instead of:
947
+ | ${" val foo = List[_](1, 2)" }
948
+ |
949
+ | Use:
950
+ | ${" val foo = List[Int](1, 2)" }
951
+ |
952
+ |- Type bounds
953
+ |
954
+ | Instead of:
955
+ | ${" def foo[T <: _](x: T) = ..." }
956
+ |
957
+ | Remove the bounds if the type doesn't matter:
958
+ | ${" def foo[T](x: T) = ..." }
959
+ |
960
+ |- ${" val" } and ${" def" } types
961
+ |
962
+ | Instead of:
963
+ | ${" val foo: _ = 3" }
964
+ |
965
+ | Use:
966
+ | ${" val foo: Int = 3" }
967
+ | """
968
+ }
926
969
}
You can’t perform that action at this time.
0 commit comments