@@ -18,18 +18,21 @@ import Constants._
1818import Scopes ._
1919import CheckRealizable ._
2020import ErrorReporting .errorTree
21+
2122import annotation .unchecked
2223import util .Positions ._
23- import util .{Stats , SimpleMap }
24+ import util .{SimpleMap , Stats }
2425import util .common ._
2526import transform .SymUtils ._
2627import Decorators ._
2728import Uniques ._
2829import ErrorReporting .{err , errorType }
2930import config .Printers .typr
31+
3032import collection .mutable
3133import 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 ._
3336import dotty .tools .dotc .transform .ValueClasses ._
3437
3538object Checking {
@@ -42,11 +45,12 @@ object Checking {
4245 def checkBounds (args : List [tpd.Tree ], boundss : List [TypeBounds ], instantiate : (Type , List [Type ]) => Type )(implicit ctx : Context ): Unit = {
4346 (args, boundss).zipped.foreach { (arg, bound) =>
4447 if (! bound.isHK && arg.tpe.isHK)
48+ // see MissingTypeParameterFor
4549 ctx.error(ex " missing type parameter(s) for $arg" , arg.pos)
4650 }
4751 for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate))
4852 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) ,
5054 arg.pos.focus)
5155 }
5256
@@ -111,18 +115,16 @@ object Checking {
111115 val stp = SkolemType (tp)
112116 val selfType = tref.givenSelfType.asSeenFrom(stp, cls)
113117 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 )
115119 }
116120 case _ =>
117121 }
118122
119123 /** Check that type `tp` is realizable. */
120124 def checkRealizable (tp : Type , pos : Position )(implicit ctx : Context ): Unit = {
121125 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)
126128 }
127129
128130 /** A type map which checks that the only cycles in a type are F-bounds
@@ -304,50 +306,46 @@ object Checking {
304306
305307 /** Check that symbol's definition is well-formed. */
306308 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)
312310
313311 def checkWithDeferred (flag : FlagSet ) =
314312 if (sym.is(flag))
315- fail(i " abstract member may not have ` $ flag' modifier " )
313+ fail(AbstractMemberMayNotHaveModifier (sym, flag) )
316314 def checkNoConflict (flag1 : FlagSet , flag2 : FlagSet ) =
317315 if (sym.is(allOf(flag1, flag2)))
318316 fail(i " illegal combination of modifiers: $flag1 and $flag2 for: $sym" )
319317
320318 if (sym.is(ImplicitCommon )) {
321319 if (sym.owner.is(Package ))
322- fail(i " `implicit' modifier cannot be used for top-level definitions " )
320+ fail(TopLevelCantBeImplicit (sym) )
323321 if (sym.isType)
324- fail(i " `implicit' modifier cannot be used for types or traits " )
322+ fail(TypesAndTraitsCantBeImplicit (sym) )
325323 }
326324 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) )
328326 if (sym.is(AbsOverride ) && ! sym.owner.is(Trait ))
329- fail(i " `abstract override' modifier only allowed for members of traits " )
327+ fail(AbstractOverrideOnlyInTraits (sym) )
330328 if (sym.is(Trait ) && sym.is(Final ))
331- fail(i " $ sym may not be `final' " )
329+ fail(TraitsMayNotBeFinal ( sym) )
332330 if (sym.hasAnnotation(defn.NativeAnnot )) {
333331 if (! sym.is(Deferred ))
334- fail(i " `@native' members may not have implementation " )
332+ fail(NativeMembersMayNotHaveImplementation (sym) )
335333 }
336334 else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
337335 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) )
339337 checkWithDeferred(Private )
340338 checkWithDeferred(Final )
341339 checkWithDeferred(Inline )
342340 }
343341 if (sym.isValueClass && sym.is(Trait ) && ! sym.isRefinementClass)
344- fail(i " $ sym cannot extend AnyVal " )
342+ fail(CannotExtendAnyVal ( sym) )
345343 checkNoConflict(Final , Sealed )
346344 checkNoConflict(Private , Protected )
347345 checkNoConflict(Abstract , Override )
348346 if (sym.isType && ! sym.is(Deferred ))
349347 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) )
351349 sym.setFlag(Private ) // break the overriding relationship by making sym Private
352350 }
353351 }
@@ -610,7 +608,7 @@ trait Checking {
610608 if (tpt.tpe.isHK && ! ctx.compilationUnit.isJava) {
611609 // be more lenient with missing type params in Java,
612610 // needed to make pos/java-interop/t1196 work.
613- errorTree(tpt, ex " missing type parameter for ${ tpt.tpe} " )
611+ errorTree(tpt, MissingTypeParameterFor ( tpt.tpe) )
614612 }
615613 else tpt
616614
0 commit comments