@@ -18,18 +18,21 @@ import Constants._
18
18
import Scopes ._
19
19
import CheckRealizable ._
20
20
import ErrorReporting .errorTree
21
+
21
22
import annotation .unchecked
22
23
import util .Positions ._
23
- import util .{Stats , SimpleMap }
24
+ import util .{SimpleMap , Stats }
24
25
import util .common ._
25
26
import transform .SymUtils ._
26
27
import Decorators ._
27
28
import Uniques ._
28
29
import ErrorReporting .{err , errorType }
29
30
import config .Printers .typr
31
+
30
32
import collection .mutable
31
33
import SymDenotations .NoCompleter
32
- import dotty .tools .dotc .reporting .diagnostic .messages .CantInstantiateAbstractClassOrTrait
34
+ import dotty .tools .dotc .reporting .diagnostic .{ErrorMessageID , Message }
35
+ import dotty .tools .dotc .reporting .diagnostic .messages ._
33
36
import dotty .tools .dotc .transform .ValueClasses ._
34
37
35
38
object Checking {
@@ -42,11 +45,12 @@ object Checking {
42
45
def checkBounds (args : List [tpd.Tree ], boundss : List [TypeBounds ], instantiate : (Type , List [Type ]) => Type )(implicit ctx : Context ): Unit = {
43
46
(args, boundss).zipped.foreach { (arg, bound) =>
44
47
if (! bound.isHK && arg.tpe.isHK)
48
+ // see MissingTypeParameterFor
45
49
ctx.error(ex " missing type parameter(s) for $arg" , arg.pos)
46
50
}
47
51
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate))
48
52
ctx.error(
49
- ex " Type argument ${ arg.tpe} does not conform to $ which bound $bound ${err.whyNoMatchStr(arg.tpe , bound)} " ,
53
+ DoesNotConformToBound ( arg.tpe, which, bound)(err) ,
50
54
arg.pos.focus)
51
55
}
52
56
@@ -111,18 +115,16 @@ object Checking {
111
115
val stp = SkolemType (tp)
112
116
val selfType = tref.givenSelfType.asSeenFrom(stp, cls)
113
117
if (selfType.exists && ! (stp <:< selfType))
114
- ctx.error(ex " $tp does not conform to its self type $ selfType; cannot be instantiated " )
118
+ ctx.error(DoesNotConformToSelfTypeCantBeInstantiated (tp, selfType), pos )
115
119
}
116
120
case _ =>
117
121
}
118
122
119
123
/** Check that type `tp` is realizable. */
120
124
def checkRealizable (tp : Type , pos : Position )(implicit ctx : Context ): Unit = {
121
125
val rstatus = realizability(tp)
122
- if (rstatus ne Realizable ) {
123
- def msg = em " $tp is not a legal path \n since it ${rstatus.msg}"
124
- if (ctx.scala2Mode) ctx.migrationWarning(msg, pos) else ctx.error(msg, pos)
125
- }
126
+ if (rstatus ne Realizable )
127
+ ctx.errorOrMigrationWarning(em " $tp is not a legal path \n since it ${rstatus.msg}" , pos)
126
128
}
127
129
128
130
/** A type map which checks that the only cycles in a type are F-bounds
@@ -304,50 +306,46 @@ object Checking {
304
306
305
307
/** Check that symbol's definition is well-formed. */
306
308
def checkWellFormed (sym : Symbol )(implicit ctx : Context ): Unit = {
307
- // println(i"check wf $sym with flags ${sym.flags}")
308
- def fail (msg : String ) = ctx.error(msg, sym.pos)
309
- def varNote =
310
- if (sym.is(Mutable )) " \n (Note that variables need to be initialized to be defined)"
311
- else " "
309
+ def fail (msg : Message ) = ctx.error(msg, sym.pos)
312
310
313
311
def checkWithDeferred (flag : FlagSet ) =
314
312
if (sym.is(flag))
315
- fail(i " abstract member may not have ` $ flag' modifier " )
313
+ fail(AbstractMemberMayNotHaveModifier (sym, flag) )
316
314
def checkNoConflict (flag1 : FlagSet , flag2 : FlagSet ) =
317
315
if (sym.is(allOf(flag1, flag2)))
318
316
fail(i " illegal combination of modifiers: $flag1 and $flag2 for: $sym" )
319
317
320
318
if (sym.is(ImplicitCommon )) {
321
319
if (sym.owner.is(Package ))
322
- fail(i " `implicit' modifier cannot be used for top-level definitions " )
320
+ fail(TopLevelCantBeImplicit (sym) )
323
321
if (sym.isType)
324
- fail(i " `implicit' modifier cannot be used for types or traits " )
322
+ fail(TypesAndTraitsCantBeImplicit (sym) )
325
323
}
326
324
if (! sym.isClass && sym.is(Abstract ))
327
- fail(i " `abstract' modifier can be used only for classes; it should be omitted for abstract members " )
325
+ fail(OnlyClassesCanBeAbstract (sym) )
328
326
if (sym.is(AbsOverride ) && ! sym.owner.is(Trait ))
329
- fail(i " `abstract override' modifier only allowed for members of traits " )
327
+ fail(AbstractOverrideOnlyInTraits (sym) )
330
328
if (sym.is(Trait ) && sym.is(Final ))
331
- fail(i " $ sym may not be `final' " )
329
+ fail(TraitsMayNotBeFinal ( sym) )
332
330
if (sym.hasAnnotation(defn.NativeAnnot )) {
333
331
if (! sym.is(Deferred ))
334
- fail(i " `@native' members may not have implementation " )
332
+ fail(NativeMembersMayNotHaveImplementation (sym) )
335
333
}
336
334
else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
337
335
if (! sym.owner.isClass || sym.owner.is(Module ) || sym.owner.isAnonymousClass)
338
- fail(i " only classes can have declared but undefined members $varNote " )
336
+ fail(OnlyClassesCanHaveDeclaredButUndefinedMembers (sym) )
339
337
checkWithDeferred(Private )
340
338
checkWithDeferred(Final )
341
339
checkWithDeferred(Inline )
342
340
}
343
341
if (sym.isValueClass && sym.is(Trait ) && ! sym.isRefinementClass)
344
- fail(i " $ sym cannot extend AnyVal " )
342
+ fail(CannotExtendAnyVal ( sym) )
345
343
checkNoConflict(Final , Sealed )
346
344
checkNoConflict(Private , Protected )
347
345
checkNoConflict(Abstract , Override )
348
346
if (sym.isType && ! sym.is(Deferred ))
349
347
for (cls <- sym.allOverriddenSymbols.filter(_.isClass)) {
350
- fail(i " $ sym cannot have the same name as ${ cls.showLocated} -- class definitions cannot be overridden " )
348
+ fail(CannotHaveSameNameAs ( sym, cls) )
351
349
sym.setFlag(Private ) // break the overriding relationship by making sym Private
352
350
}
353
351
}
@@ -610,7 +608,7 @@ trait Checking {
610
608
if (tpt.tpe.isHK && ! ctx.compilationUnit.isJava) {
611
609
// be more lenient with missing type params in Java,
612
610
// needed to make pos/java-interop/t1196 work.
613
- errorTree(tpt, ex " missing type parameter for ${ tpt.tpe} " )
611
+ errorTree(tpt, MissingTypeParameterFor ( tpt.tpe) )
614
612
}
615
613
else tpt
616
614
0 commit comments