@@ -54,6 +54,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
5454 final ir.ClassHierarchy hierarchy;
5555
5656 ThisInterfaceType _thisType;
57+ ir.Library _currentLibrary;
5758
5859 StaticTypeVisitor (ir.TypeEnvironment typeEnvironment, this .hierarchy)
5960 : super (typeEnvironment);
@@ -83,6 +84,16 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
8384 _thisType = value;
8485 }
8586
87+ ir.Library get currentLibrary {
88+ assert (_currentLibrary != null );
89+ return _currentLibrary;
90+ }
91+
92+ void set currentLibrary (ir.Library value) {
93+ assert (value == null || _currentLibrary == null );
94+ _currentLibrary = value;
95+ }
96+
8697 bool completes (ir.DartType type) => type != const DoesNotCompleteType ();
8798
8899 Set <ir.VariableDeclaration > _currentVariables;
@@ -173,7 +184,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
173184 /// If this is not the case the raw type of [superclass] is returned.
174185 ///
175186 /// This method is derived from `ir.Expression.getStaticTypeAsInstanceOf` .
176- ir.InterfaceType getTypeAsInstanceOf (ir.DartType type, ir.Class superclass) {
187+ ir.InterfaceType getTypeAsInstanceOf (
188+ ir.DartType type, ir.Class superclass, ir.Library clientLibrary) {
177189 // This method assumes the program is correctly typed, so if the superclass
178190 // is not generic, we can just return its raw type without computing the
179191 // type of this expression. It also ensures that all types are considered
@@ -186,14 +198,16 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
186198 type = (type as ir.TypeParameterType ).parameter.bound;
187199 }
188200 if (type == typeEnvironment.nullType) {
189- return superclass.bottomType;
201+ return typeEnvironment.coreTypes
202+ .bottomInterfaceType (superclass, ir.Nullability .legacy);
190203 }
191204 if (type is ir.InterfaceType ) {
192- ir.InterfaceType upcastType =
193- typeEnvironment. getTypeAsInstanceOf ( type, superclass);
205+ ir.InterfaceType upcastType = typeEnvironment. getTypeAsInstanceOf (
206+ type, superclass, clientLibrary, typeEnvironment.coreTypes );
194207 if (upcastType != null ) return upcastType;
195208 } else if (type is ir.BottomType ) {
196- return superclass.bottomType;
209+ return typeEnvironment.coreTypes
210+ .bottomInterfaceType (superclass, ir.Nullability .legacy);
197211 }
198212 // TODO(johnniwinther): Should we assert that this doesn't happen?
199213 return typeEnvironment.coreTypes.legacyRawType (superclass);
@@ -213,7 +227,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
213227 }
214228 if (interfaceTarget != null ) {
215229 ir.Class superclass = interfaceTarget.enclosingClass;
216- receiverType = getTypeAsInstanceOf (receiverType, superclass);
230+ receiverType =
231+ getTypeAsInstanceOf (receiverType, superclass, currentLibrary);
217232 return ir.Substitution .fromInterfaceType (receiverType)
218233 .substituteType (interfaceTarget.getterType);
219234 }
@@ -283,7 +298,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
283298 ir.Class superclass = interfaceTarget.enclosingClass;
284299 ir.Substitution receiverSubstitution =
285300 ir.Substitution .fromInterfaceType (
286- getTypeAsInstanceOf (receiverType, superclass));
301+ getTypeAsInstanceOf (receiverType, superclass, currentLibrary ));
287302 ir.DartType setterType =
288303 receiverSubstitution.substituteType (interfaceTarget.setterType);
289304 if (! typeEnvironment.isSubtypeOf (
@@ -316,7 +331,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
316331 ir.DartType visitDirectPropertyGet (ir.DirectPropertyGet node) {
317332 ir.DartType receiverType = visitNode (node.receiver);
318333 ir.Class superclass = node.target.enclosingClass;
319- receiverType = getTypeAsInstanceOf (receiverType, superclass);
334+ receiverType =
335+ getTypeAsInstanceOf (receiverType, superclass, currentLibrary);
320336 ir.DartType resultType = ir.Substitution .fromInterfaceType (receiverType)
321337 .substituteType (node.target.getterType);
322338 _expressionTypeCache[node] = resultType;
@@ -341,7 +357,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
341357 receiverType, argumentType);
342358 } else {
343359 ir.Class superclass = node.target.enclosingClass;
344- receiverType = getTypeAsInstanceOf (receiverType, superclass);
360+ receiverType =
361+ getTypeAsInstanceOf (receiverType, superclass, currentLibrary);
345362 ir.DartType returnType = ir.Substitution .fromInterfaceType (receiverType)
346363 .substituteType (node.target.function.returnType);
347364 returnType = ir.Substitution .fromPairs (
@@ -597,7 +614,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
597614 if (interfaceTarget != null ) {
598615 ir.Class superclass = interfaceTarget.enclosingClass;
599616 ir.Substitution receiverSubstitution = ir.Substitution .fromInterfaceType (
600- getTypeAsInstanceOf (receiverType, superclass));
617+ getTypeAsInstanceOf (receiverType, superclass, currentLibrary ));
601618 ir.DartType getterType =
602619 receiverSubstitution.substituteType (interfaceTarget.getterType);
603620 if (getterType is ir.FunctionType ) {
@@ -810,8 +827,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
810827 if (declaringClass.typeParameters.isEmpty) {
811828 resultType = node.interfaceTarget.getterType;
812829 } else {
813- ir.DartType receiver =
814- typeEnvironment. getTypeAsInstanceOf (thisType, declaringClass );
830+ ir.DartType receiver = typeEnvironment. getTypeAsInstanceOf (thisType,
831+ declaringClass, currentLibrary, typeEnvironment.coreTypes );
815832 resultType = ir.Substitution .fromInterfaceType (receiver)
816833 .substituteType (node.interfaceTarget.getterType);
817834 }
@@ -843,8 +860,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
843860 returnType = const ir.DynamicType ();
844861 } else {
845862 ir.Class superclass = node.interfaceTarget.enclosingClass;
846- ir.InterfaceType receiverType =
847- typeEnvironment. getTypeAsInstanceOf ( thisType, superclass);
863+ ir.InterfaceType receiverType = typeEnvironment. getTypeAsInstanceOf (
864+ thisType, superclass, currentLibrary, typeEnvironment.coreTypes );
848865 returnType = ir.Substitution .fromInterfaceType (receiverType)
849866 .substituteType (node.interfaceTarget.function.returnType);
850867 returnType = ir.Substitution .fromPairs (
@@ -1216,7 +1233,10 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
12161233 if (node.isAsync) {
12171234 ir.InterfaceType streamInterfaceType = getInterfaceTypeOf (iterableType);
12181235 ir.InterfaceType streamType = typeEnvironment.getTypeAsInstanceOf (
1219- streamInterfaceType, typeEnvironment.coreTypes.streamClass);
1236+ streamInterfaceType,
1237+ typeEnvironment.coreTypes.streamClass,
1238+ currentLibrary,
1239+ typeEnvironment.coreTypes);
12201240 if (streamType != null ) {
12211241 iteratorType = new ir.InterfaceType (
12221242 typeEnvironment.coreTypes.streamIteratorClass,
@@ -1230,7 +1250,10 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
12301250 if (member != null ) {
12311251 iteratorType = ir.Substitution .fromInterfaceType (
12321252 typeEnvironment.getTypeAsInstanceOf (
1233- iterableInterfaceType, member.enclosingClass))
1253+ iterableInterfaceType,
1254+ member.enclosingClass,
1255+ currentLibrary,
1256+ typeEnvironment.coreTypes))
12341257 .substituteType (member.getterType);
12351258 }
12361259 }
@@ -1382,12 +1405,14 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
13821405 thisType = new ThisInterfaceType .from (node.enclosingClass? .getThisType (
13831406 typeEnvironment.coreTypes, node.enclosingLibrary.nonNullable));
13841407 _currentVariables = {};
1408+ currentLibrary = node.enclosingLibrary;
13851409 visitSignature (node.function);
13861410 visitNode (node.function.body);
13871411 handleProcedure (node);
13881412 _invalidatedVariables.removeAll (_currentVariables);
13891413 _currentVariables = null ;
13901414 thisType = null ;
1415+ currentLibrary = null ;
13911416 }
13921417
13931418 void handleConstructor (ir.Constructor node) {}
@@ -1397,13 +1422,15 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
13971422 thisType = new ThisInterfaceType .from (node.enclosingClass.getThisType (
13981423 typeEnvironment.coreTypes, node.enclosingLibrary.nonNullable));
13991424 _currentVariables = {};
1425+ currentLibrary = node.enclosingLibrary;
14001426 visitSignature (node.function);
14011427 visitNodes (node.initializers);
14021428 visitNode (node.function.body);
14031429 handleConstructor (node);
14041430 _invalidatedVariables.removeAll (_currentVariables);
14051431 _currentVariables = null ;
14061432 thisType = null ;
1433+ currentLibrary = null ;
14071434 }
14081435
14091436 void handleField (ir.Field node) {}
@@ -1413,11 +1440,13 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
14131440 thisType = new ThisInterfaceType .from (node.enclosingClass? .getThisType (
14141441 typeEnvironment.coreTypes, node.enclosingLibrary.nonNullable));
14151442 _currentVariables = {};
1443+ currentLibrary = node.enclosingLibrary;
14161444 visitNode (node.initializer);
14171445 handleField (node);
14181446 _invalidatedVariables.removeAll (_currentVariables);
14191447 _currentVariables = null ;
14201448 thisType = null ;
1449+ currentLibrary = null ;
14211450 }
14221451
14231452 void handleVariableDeclaration (ir.VariableDeclaration node) {}
0 commit comments