File tree Expand file tree Collapse file tree 4 files changed +54
-6
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ public enum ErrorMessageID {
51
51
ExpectedTokenButFoundID ,
52
52
MixedLeftAndRightAssociativeOpsID ,
53
53
CantInstantiateAbstractClassOrTraitID ,
54
+ OverloadedOrRecursiveMethodNeedsResultTypeID ,
55
+ RecursiveValueNeedsResultTypeID ,
56
+ CyclicReferenceInvolvingImplicitID ,
54
57
;
55
58
56
59
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1146,4 +1146,32 @@ object messages {
1146
1146
| """ .stripMargin
1147
1147
}
1148
1148
1149
+ case class OverloadedOrRecursiveMethodNeedsResultType (tree : Names .TermName )(implicit ctx : Context )
1150
+ extends Message (OverloadedOrRecursiveMethodNeedsResultTypeID ) {
1151
+ val kind = " Syntax"
1152
+ val msg = hl """ overloaded or recursive method ${tree} needs result type """
1153
+ val explanation =
1154
+ hl """ """ .stripMargin
1155
+ }
1156
+
1157
+ case class RecursiveValueNeedsResultType (tree : Names .TermName )(implicit ctx : Context )
1158
+ extends Message (RecursiveValueNeedsResultTypeID ) {
1159
+ val kind = " Syntax"
1160
+ val msg = hl """ recursive value ${tree.name} needs type """
1161
+ val explanation =
1162
+ hl """ """ .stripMargin
1163
+ }
1164
+
1165
+ case class CyclicReferenceInvolvingImplicit (cycleSym : Symbol )(implicit ctx : Context )
1166
+ extends Message (CyclicReferenceInvolvingImplicitID ) {
1167
+ val kind = " Syntax"
1168
+ val msg = hl """ cyclic reference involving implicit $cycleSym"""
1169
+ val explanation =
1170
+ hl """ |This happens when the right hand-side of $cycleSym's definition involves an implicit search.
1171
+ |To avoid the error, give $cycleSym an explicit type.
1172
+ | """ .stripMargin
1173
+ }
1174
+
1175
+
1176
+
1149
1177
}
Original file line number Diff line number Diff line change @@ -28,22 +28,20 @@ object ErrorReporting {
28
28
29
29
def cyclicErrorMsg (ex : CyclicReference )(implicit ctx : Context ) = {
30
30
val cycleSym = ex.denot.symbol
31
- def errorMsg (msg : String , cx : Context ): String =
31
+ def errorMsg (msg : String , cx : Context ): Message =
32
32
if (cx.mode is Mode .InferringReturnType ) {
33
33
cx.tree match {
34
34
case tree : untpd.DefDef if ! tree.tpt.typeOpt.exists =>
35
- em " overloaded or recursive method ${ tree.name} needs result type "
35
+ OverloadedOrRecursiveMethodNeedsResultType ( tree.name)
36
36
case tree : untpd.ValDef if ! tree.tpt.typeOpt.exists =>
37
- em " recursive value ${ tree.name} needs type "
37
+ RecursiveValueNeedsResultType ( tree.name)
38
38
case _ =>
39
39
errorMsg(msg, cx.outer)
40
40
}
41
41
} else msg
42
42
43
43
if (cycleSym.is(Implicit , butNot = Method ) && cycleSym.owner.isTerm)
44
- em """ cyclic reference involving implicit $cycleSym
45
- |This happens when the right hand-side of $cycleSym's definition involves an implicit search.
46
- |To avoid the error, give $cycleSym an explicit type. """
44
+ CyclicReferenceInvolvingImplicit (cycleSym)
47
45
else
48
46
errorMsg(ex.show, ctx)
49
47
}
Original file line number Diff line number Diff line change @@ -198,4 +198,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
198
198
assertTrue(" expected trait" , isTrait)
199
199
}
200
200
201
+ @ Test def cantInstantiateTrait =
202
+ checkMessagesAfter(" refchecks" ) {
203
+ """
204
+ |object Scope {
205
+ | trait Concept
206
+ | new Concept()
207
+ |}
208
+ """ .stripMargin
209
+ }
210
+ .expect { (ictx, messages) =>
211
+ implicit val ctx : Context = ictx
212
+ val defn = ictx.definitions
213
+
214
+ assertMessageCount(1 , messages)
215
+ val CantInstantiateAbstractClassOrTrait (cls, isTrait) :: Nil = messages
216
+ assertEquals(" Concept" , cls.name.show)
217
+ assertTrue(" expected trait" , isTrait)
218
+ }
219
+
201
220
}
You can’t perform that action at this time.
0 commit comments