@@ -168,8 +168,6 @@ class Semantic {
168
168
extension (trace : Trace )
169
169
def add (node : Tree ): Trace = trace :+ node
170
170
171
- val noErrors = Nil
172
-
173
171
// ----- Operations on domains -----------------------------
174
172
extension (a : Value )
175
173
def join (b : Value ): Value =
@@ -199,7 +197,7 @@ class Semantic {
199
197
def select (field : Symbol , source : Tree ): Contextual [Result ] =
200
198
value match {
201
199
case Hot =>
202
- Result (Hot , noErrors )
200
+ Result (Hot , Errors .empty )
203
201
204
202
case Cold =>
205
203
val error = AccessCold (field, source, trace)
@@ -236,7 +234,7 @@ class Semantic {
236
234
def call (meth : Symbol , superType : Type , source : Tree ): Contextual [Result ] =
237
235
value match {
238
236
case Hot =>
239
- Result (Hot , noErrors )
237
+ Result (Hot , Errors .empty )
240
238
241
239
case Cold =>
242
240
val error = CallCold (meth, source, trace)
@@ -306,7 +304,7 @@ class Semantic {
306
304
def instantiate (klass : ClassSymbol , ctor : Symbol , source : Tree ): Contextual [Result ] =
307
305
value match {
308
306
case Hot =>
309
- Result (Hot , noErrors )
307
+ Result (Hot , Errors .empty )
310
308
311
309
case Cold =>
312
310
val error = CallCold (ctor, source, trace)
@@ -390,12 +388,12 @@ class Semantic {
390
388
value match
391
389
case Hot => Nil
392
390
393
- case Cold => PromoteCold ( source, trace) :: Nil
391
+ case Cold => PromoteError (msg, source, trace) :: Nil
394
392
395
393
case thisRef : ThisRef =>
396
394
if heap.promotedValues.contains(thisRef) then Nil
397
395
else if thisRef.canPromoteExtrinsic then Nil
398
- else PromoteThis ( source, trace) :: Nil
396
+ else PromoteError (msg, source, trace) :: Nil
399
397
400
398
case warm : Warm =>
401
399
if heap.promotedValues.contains(warm) then Nil
@@ -413,7 +411,7 @@ class Semantic {
413
411
val res = eval(body, thisV, klass)
414
412
val errors2 = res.value.promote(msg, source)
415
413
if (res.errors.nonEmpty || errors2.nonEmpty)
416
- UnsafePromotion (source, trace, res.errors ++ errors2) :: Nil
414
+ UnsafePromotion (msg, source, trace, res.errors ++ errors2) :: Nil
417
415
else
418
416
heap.promotedValues += fun
419
417
Nil
@@ -443,7 +441,7 @@ class Semantic {
443
441
def tryPromote (msg : String , source : Tree ): Contextual [List [Error ]] = log(" promote " + warm.show, printer) {
444
442
val classRef = warm.klass.appliedRef
445
443
if classRef.memberClasses.nonEmpty then
446
- return PromoteWarm ( source, trace) :: Nil
444
+ return PromoteError (msg, source, trace) :: Nil
447
445
448
446
val fields = classRef.fields
449
447
val methods = classRef.membersBasedOnFlags(Flags .Method , Flags .Deferred | Flags .Accessor )
@@ -466,7 +464,7 @@ class Semantic {
466
464
}
467
465
468
466
if buffer.isEmpty then Nil
469
- else UnsafePromotion (source, trace, buffer.toList) :: Nil
467
+ else UnsafePromotion (msg, source, trace, buffer.toList) :: Nil
470
468
}
471
469
472
470
end extension
@@ -502,7 +500,7 @@ class Semantic {
502
500
*/
503
501
def eval (expr : Tree , thisV : Value , klass : ClassSymbol , cacheResult : Boolean = false ): Contextual [Result ] = log(" evaluating " + expr.show + " , this = " + thisV.show, printer, res => res.asInstanceOf [Result ].show) {
504
502
val innerMap = cache.getOrElseUpdate(thisV, new EqHashMap [Tree , Value ])
505
- if (innerMap.contains(expr)) Result (innerMap(expr), noErrors )
503
+ if (innerMap.contains(expr)) Result (innerMap(expr), Errors .empty )
506
504
else {
507
505
// no need to compute fix-point, because
508
506
// 1. the result is decided by `cfg` for a legal program
@@ -544,7 +542,7 @@ class Semantic {
544
542
expr match {
545
543
case Ident (nme.WILDCARD ) =>
546
544
// TODO: disallow `var x: T = _`
547
- Result (Hot , noErrors )
545
+ Result (Hot , Errors .empty )
548
546
549
547
case id @ Ident (name) if ! id.symbol.is(Flags .Method ) =>
550
548
assert(name.isTermName, " type trees should not reach here" )
@@ -596,10 +594,10 @@ class Semantic {
596
594
cases(expr.tpe, thisV, klass, expr)
597
595
598
596
case Literal (_) =>
599
- Result (Hot , noErrors )
597
+ Result (Hot , Errors .empty )
600
598
601
599
case Typed (expr, tpt) =>
602
- if (tpt.tpe.hasAnnotation(defn.UncheckedAnnot )) Result (Hot , noErrors )
600
+ if (tpt.tpe.hasAnnotation(defn.UncheckedAnnot )) Result (Hot , Errors .empty )
603
601
else eval(expr, thisV, klass) ++ checkTermUsage(tpt, thisV, klass)
604
602
605
603
case NamedArg (name, arg) =>
@@ -609,9 +607,9 @@ class Semantic {
609
607
lhs match
610
608
case Select (qual, _) =>
611
609
val res = eval(qual, thisV, klass)
612
- eval(rhs, thisV, klass).ensureHot(" May only assign initialized value" , rhs) ++ res.errors
610
+ eval(rhs, thisV, klass).ensureHot(" May only assign fully initialized value" , rhs) ++ res.errors
613
611
case id : Ident =>
614
- eval(rhs, thisV, klass).ensureHot(" May only assign initialized value" , rhs)
612
+ eval(rhs, thisV, klass).ensureHot(" May only assign fully initialized value" , rhs)
615
613
616
614
case closureDef(ddef) =>
617
615
thisV match
@@ -645,11 +643,11 @@ class Semantic {
645
643
Result (value, errors)
646
644
647
645
case Annotated (arg, annot) =>
648
- if (expr.tpe.hasAnnotation(defn.UncheckedAnnot )) Result (Hot , noErrors )
646
+ if (expr.tpe.hasAnnotation(defn.UncheckedAnnot )) Result (Hot , Errors .empty )
649
647
else eval(arg, thisV, klass)
650
648
651
649
case Match (selector, cases) =>
652
- val res1 = eval(selector, thisV, klass).ensureHot(" The value to be matched needs to be initialized" , selector)
650
+ val res1 = eval(selector, thisV, klass).ensureHot(" The value to be matched needs to be fully initialized" , selector)
653
651
val ress = eval(cases.map(_.body), thisV, klass)
654
652
val value = ress.map(_.value).join
655
653
val errors = res1.errors ++ ress.flatMap(_.errors)
@@ -678,7 +676,7 @@ class Semantic {
678
676
679
677
case SeqLiteral (elems, elemtpt) =>
680
678
val ress = elems.map { elem =>
681
- eval(elem, thisV, klass).ensureHot(" May only use initialized value as arguments" , elem)
679
+ eval(elem, thisV, klass).ensureHot(" May only use initialized value as method arguments" , elem)
682
680
}
683
681
Result (Hot , ress.flatMap(_.errors))
684
682
@@ -688,7 +686,7 @@ class Semantic {
688
686
689
687
case Thicket (List ()) =>
690
688
// possible in try/catch/finally, see tests/crash/i6914.scala
691
- Result (Hot , noErrors )
689
+ Result (Hot , Errors .empty )
692
690
693
691
case vdef : ValDef =>
694
692
// local val definition
@@ -697,11 +695,11 @@ class Semantic {
697
695
698
696
case ddef : DefDef =>
699
697
// local method
700
- Result (Hot , noErrors )
698
+ Result (Hot , Errors .empty )
701
699
702
700
case tdef : TypeDef =>
703
701
// local type definition
704
- if tdef.isClassDef then Result (Hot , noErrors )
702
+ if tdef.isClassDef then Result (Hot , Errors .empty )
705
703
else Result (Hot , checkTermUsage(tdef.rhs, thisV, klass))
706
704
707
705
case tpl : Template =>
@@ -710,7 +708,7 @@ class Semantic {
710
708
case _ => ??? // impossible
711
709
712
710
case _ : Import | _ : Export =>
713
- Result (Hot , noErrors )
711
+ Result (Hot , Errors .empty )
714
712
715
713
case _ =>
716
714
throw new Exception (" unexpected tree: " + expr.show)
@@ -720,23 +718,23 @@ class Semantic {
720
718
def cases (tp : Type , thisV : Value , klass : ClassSymbol , source : Tree ): Contextual [Result ] = log(" evaluating " + tp.show, printer, res => res.asInstanceOf [Result ].show) {
721
719
tp match {
722
720
case _ : ConstantType =>
723
- Result (Hot , noErrors )
721
+ Result (Hot , Errors .empty )
724
722
725
723
case tmref : TermRef if tmref.prefix == NoPrefix =>
726
- Result (Hot , noErrors )
724
+ Result (Hot , Errors .empty )
727
725
728
726
case tmref : TermRef =>
729
727
cases(tmref.prefix, thisV, klass, source).select(tmref.symbol, source)
730
728
731
729
case tp @ ThisType (tref) =>
732
- if tref.symbol.is(Flags .Package ) then Result (Hot , noErrors )
730
+ if tref.symbol.is(Flags .Package ) then Result (Hot , Errors .empty )
733
731
else
734
732
val value = resolveThis(tref.classSymbol.asClass, thisV, klass, source)
735
- Result (value, noErrors )
733
+ Result (value, Errors .empty )
736
734
737
735
case _ : TermParamRef | _ : RecThis =>
738
736
// possible from checking effects of types
739
- Result (Hot , noErrors )
737
+ Result (Hot , Errors .empty )
740
738
741
739
case _ =>
742
740
throw new Exception (" unexpected type: " + tp)
@@ -774,7 +772,7 @@ class Semantic {
774
772
if tref.prefix == NoPrefix then
775
773
val enclosing = cls.owner.lexicallyEnclosingClass.asClass
776
774
val outerV = resolveThis(enclosing, thisV, klass, source)
777
- Result (outerV, noErrors )
775
+ Result (outerV, Errors .empty )
778
776
else
779
777
cases(tref.prefix, thisV, klass, source)
780
778
0 commit comments