Skip to content

Commit acac9ab

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 37608. Use instantiated FunctionType for tear-off(s).
I was working of switching runtimeTypeMatch() to purely typeSystem.isSubtypeOf(), without working around dartbug.com/35993 and dartbug.com/33441, but bots were failing. I think that was because of this issue with incorrect tear-off types. We have to fix it before switching to less generous TypeSystem. [email protected], [email protected] Bug: #37608 Change-Id: I1f5dfc5e86553a352d72e772e791978772fe8fa4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118379 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent dbefc6c commit acac9ab

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
16181618
/// Return the constant value of the static constant represented by the given
16191619
/// [element]. The [node] is the node to be used if an error needs to be
16201620
/// reported.
1621-
DartObjectImpl _getConstantValue(AstNode node, Element element) {
1621+
DartObjectImpl _getConstantValue(Expression node, Element element) {
16221622
Element variableElement =
16231623
element is PropertyAccessorElement ? element.variable : element;
16241624
if (variableElement is VariableElementImpl) {
@@ -1634,11 +1634,8 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
16341634
} else if (variableElement is ExecutableElement) {
16351635
ExecutableElement function = element;
16361636
if (function.isStatic) {
1637-
ParameterizedType functionType = function.type;
1638-
if (functionType == null) {
1639-
functionType = _typeProvider.functionType;
1640-
}
1641-
return new DartObjectImpl(functionType, new FunctionState(function));
1637+
var functionType = node.staticType;
1638+
return DartObjectImpl(functionType, FunctionState(function));
16421639
}
16431640
} else if (variableElement is ClassElement) {
16441641
var type = variableElement.instantiate(

pkg/analyzer/lib/src/dart/constant/utilities.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ class ConstantAstCloner extends AstCloner {
8989
return literal;
9090
}
9191

92+
@override
93+
PrefixedIdentifier visitPrefixedIdentifier(PrefixedIdentifier node) {
94+
PrefixedIdentifierImpl copy = super.visitPrefixedIdentifier(node);
95+
copy.staticType = node.staticType;
96+
return copy;
97+
}
98+
99+
@override
100+
PropertyAccess visitPropertyAccess(PropertyAccess node) {
101+
PropertyAccessImpl copy = super.visitPropertyAccess(node);
102+
copy.staticType = node.staticType;
103+
return copy;
104+
}
105+
92106
@override
93107
RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
94108
RedirectingConstructorInvocation node) {
@@ -110,9 +124,11 @@ class ConstantAstCloner extends AstCloner {
110124

111125
@override
112126
SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
113-
SimpleIdentifier identifier = super.visitSimpleIdentifier(node);
114-
identifier.staticElement = node.staticElement;
115-
return identifier;
127+
SimpleIdentifierImpl copy = super.visitSimpleIdentifier(node);
128+
copy.staticElement = node.staticElement;
129+
copy.staticType = node.staticType;
130+
copy.tearOffTypeArgumentTypes = node.tearOffTypeArgumentTypes;
131+
return copy;
116132
}
117133

118134
@override

pkg/analyzer/test/id_tests/constant_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ConstantsDataExtractor extends AstDataExtractor<String> {
8888
}
8989
} else if (type is FunctionType) {
9090
var element = value.toFunctionValue();
91-
return 'Function(${element.name})';
91+
return 'Function(${element.name},type=${value.type})';
9292
}
9393
throw UnimplementedError('_stringify for type $type');
9494
}

pkg/front_end/test/constants/data/function.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ const Map<String, int> Function(String, int) instantiation1 =
1414
/*cfe.Instantiation(method2<String,int>)*/ method2;
1515

1616
main() {
17-
print(/*Function(method1)*/ function0);
18-
// TODO(paulberry): analyzer should record instantiation information. See
19-
// dartbug.com/37608.
17+
print(
18+
/*cfe|dart2js.Function(method1)*/
19+
/*analyzer.Function(method1,type=T Function<T>(T))*/
20+
function0);
2021
print(
2122
/*cfe|dart2js.Instantiation(method1<int>)*/
22-
/*analyzer.Function(method1)*/
23+
/*analyzer.Function(method1,type=int Function(int))*/
2324
instantiation0);
2425
print(
2526
/*cfe|dart2js.Instantiation(method2<String,int>)*/
26-
/*analyzer.Function(method2)*/
27+
/*analyzer.Function(method2,type=Map<String, int> Function(String, int))*/
2728
instantiation1);
2829
}

0 commit comments

Comments
 (0)