@@ -695,7 +695,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
695
695
push (arguments);
696
696
_buildConstructorReferenceInvocation (
697
697
beginToken.next! , beginToken.offset, Constness .explicitConst,
698
- inMetadata: true );
698
+ inMetadata: true , inImplicitCreationContext : false );
699
699
push (popForValue ());
700
700
} else {
701
701
pop (); // Name last identifier
@@ -4792,12 +4792,12 @@ class BodyBuilder extends ScopeListener<JumpTarget>
4792
4792
debugEvent ("NewExpression" );
4793
4793
_buildConstructorReferenceInvocation (
4794
4794
token.next! , token.offset, Constness .explicitNew,
4795
- inMetadata: false );
4795
+ inMetadata: false , inImplicitCreationContext : false );
4796
4796
}
4797
4797
4798
4798
void _buildConstructorReferenceInvocation (
4799
4799
Token nameToken, int offset, Constness constness,
4800
- {required bool inMetadata}) {
4800
+ {required bool inMetadata, required bool inImplicitCreationContext }) {
4801
4801
assert (checkState (nameToken, [
4802
4802
/*arguments*/ ValueKinds .Arguments ,
4803
4803
/*constructor name identifier*/ ValueKinds .IdentifierOrNull ,
@@ -4828,15 +4828,17 @@ class BodyBuilder extends ScopeListener<JumpTarget>
4828
4828
ConstantContext savedConstantContext = pop () as ConstantContext ;
4829
4829
if (type is Generator ) {
4830
4830
push (type.invokeConstructor (
4831
- typeArguments, name, arguments, nameToken, nameLastToken, constness));
4831
+ typeArguments, name, arguments, nameToken, nameLastToken, constness,
4832
+ inImplicitCreationContext: inImplicitCreationContext));
4832
4833
} else if (type is ParserRecovery ) {
4833
4834
push (new ParserErrorGenerator (
4834
4835
this , nameToken, fasta.messageSyntheticToken));
4835
4836
} else if (type is Expression ) {
4836
4837
push (createInstantiationAndInvocation (
4837
4838
() => type, typeArguments, name, name, arguments,
4838
4839
instantiationOffset: offset,
4839
- invocationOffset: nameLastToken.charOffset));
4840
+ invocationOffset: nameLastToken.charOffset,
4841
+ inImplicitCreationContext: inImplicitCreationContext));
4840
4842
} else {
4841
4843
String ? typeName;
4842
4844
if (type is ProblemBuilder ) {
@@ -4863,8 +4865,9 @@ class BodyBuilder extends ScopeListener<JumpTarget>
4863
4865
String constructorName,
4864
4866
Arguments arguments,
4865
4867
{required int instantiationOffset,
4866
- required int invocationOffset}) {
4867
- if (enableConstructorTearOffsInLibrary) {
4868
+ required int invocationOffset,
4869
+ required bool inImplicitCreationContext}) {
4870
+ if (enableConstructorTearOffsInLibrary && inImplicitCreationContext) {
4868
4871
Expression receiver = receiverFunction ();
4869
4872
if (typeArguments != null ) {
4870
4873
receiver = forest.createInstantiation (instantiationOffset, receiver,
@@ -4892,7 +4895,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
4892
4895
debugEvent ("ImplicitCreationExpression" );
4893
4896
_buildConstructorReferenceInvocation (
4894
4897
token.next! , token.offset, Constness .implicit,
4895
- inMetadata: false );
4898
+ inMetadata: false , inImplicitCreationContext : true );
4896
4899
}
4897
4900
4898
4901
@override
@@ -5159,7 +5162,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
5159
5162
debugEvent ("endConstExpression" );
5160
5163
_buildConstructorReferenceInvocation (
5161
5164
token.next! , token.offset, Constness .explicitConst,
5162
- inMetadata: false );
5165
+ inMetadata: false , inImplicitCreationContext : false );
5163
5166
}
5164
5167
5165
5168
@override
0 commit comments