@@ -133,6 +133,12 @@ object Objects:
133
133
134
134
def hasOuter (cls : ClassSymbol ): Boolean = outers.contains(cls)
135
135
136
+ /**
137
+ * Whether the given symbol is a member of the underlying object?
138
+ */
139
+ def hasMember (sym : Symbol )(using Context ): Boolean =
140
+ klass.isSubClass(sym.owner)
141
+
136
142
def initVal (field : Symbol , value : Value )(using Context ) = log(" Initialize " + field.show + " = " + value + " for " + this , printer) {
137
143
assert(! field.is(Flags .Mutable ), " Field is mutable: " + field.show)
138
144
assert(! vals.contains(field), " Field already set: " + field.show)
@@ -171,7 +177,7 @@ object Objects:
171
177
172
178
def show (using Context ) =
173
179
val valFields = vals.map(_.show + " -> " + _.show)
174
- " OfClass(" + klass.show + " , outer = " + outer + " , args = " + args.map(_.show) + " , vals = " + valFields + " )"
180
+ " OfClass(" + klass.show + " , outer = " + outer + " , args = " + args.map(_.show) + " , vals = " + valFields + " , vars = " + vars + " )"
175
181
176
182
object OfClass :
177
183
def apply (
@@ -612,7 +618,7 @@ object Objects:
612
618
* @param needResolve Whether the target of the call needs resolution?
613
619
*/
614
620
def call (value : Value , meth : Symbol , args : List [ArgInfo ], receiver : Type , superType : Type , needResolve : Boolean = true ): Contextual [Value ] = log(" call " + meth.show + " , this = " + value.show + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
615
- value match
621
+ value. match
616
622
case Cold =>
617
623
report.warning(" Using cold alias. " + Trace .show, Trace .position)
618
624
Bottom
@@ -786,19 +792,19 @@ object Objects:
786
792
else
787
793
errorReadOtherStaticObject(State .currentObject, addr.owner)
788
794
Bottom
789
- else if ref.isObjectRef && ref.klass.hasSource then
795
+ else if ref.hasMember(target) && ! target.isOneOf( Flags . JavaDefined , Flags . Scala2x ) then
790
796
report.warning(" Access uninitialized field " + field.show + " . " + Trace .show, Trace .position)
791
797
Bottom
792
798
else
793
- // initialization error, reported by the initialization checker
799
+ // Silent for invalid member selection from pattern matching, type cast
794
800
Bottom
795
801
else if ref.hasVal(target) then
796
802
ref.valValue(target)
797
- else if ref.isObjectRef && ref.klass.hasSource then
803
+ else if ref.hasMember(target) && ! target.isOneOf( Flags . JavaDefined , Flags . Scala2x ) then
798
804
report.warning(" Access uninitialized field " + field.show + " . " + Trace .show, Trace .position)
799
805
Bottom
800
806
else
801
- // initialization error, reported by the initialization checker
807
+ // Silent for invalid member selection from pattern matching, type cast
802
808
Bottom
803
809
804
810
else
@@ -856,7 +862,7 @@ object Objects:
856
862
errorMutateOtherStaticObject(State .currentObject, addr.owner)
857
863
else
858
864
Heap .writeJoin(addr, rhs)
859
- else
865
+ else if ref.hasMember(field) && ! field.isOneOf( Flags . JavaDefined , Flags . Scala2x ) then
860
866
report.warning(" Mutating a field before its initialization: " + field.show + " . " + Trace .show, Trace .position)
861
867
end match
862
868
0 commit comments