[cfe] Handle RecordType in isInstantiatedVisitor

Closes #50021

Change-Id: Ifb608247d0ecef3de4388bec7891afc8be00f998
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260112
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2022-09-21 12:07:36 +00:00 committed by Commit Bot
parent b85443e333
commit 24c8a19439
10 changed files with 140 additions and 1 deletions

View file

@ -4679,7 +4679,7 @@ bool isInstantiated(DartType type) {
return type.accept(new IsInstantiatedVisitor());
}
class IsInstantiatedVisitor extends DartTypeVisitor<bool> {
class IsInstantiatedVisitor implements DartTypeVisitor<bool> {
final _availableVariables = new Set<TypeParameter>();
bool isInstantiated(DartType type) {
@ -4739,6 +4739,23 @@ class IsInstantiatedVisitor extends DartTypeVisitor<bool> {
@override
bool visitNeverType(NeverType node) => true;
@override
bool visitRecordType(RecordType node) {
return node.positional.every((p) => p.accept(this)) &&
node.named.every((p) => p.type.accept(this));
}
@override
bool visitExtensionType(ExtensionType node) {
return node.typeArguments
.every((DartType typeArgument) => typeArgument.accept(this));
}
@override
bool visitIntersectionType(IntersectionType node) {
return node.left.accept(this) && node.right.accept(this);
}
}
bool _isFormalParameter(VariableDeclaration variable) {

View file

@ -0,0 +1,11 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class C<T> {
void method() {
C<(num, {String name})>.new; // Const
C<(T, {String name})>.new; // Non-const
C<(num, {T name})>.new; // Non-const
}
}

View file

@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
: super core::Object::•()
;
method method() → void {
#C2;
#C1<(self::C::T%, {required name: core::String})>;
#C1<(core::num, {required name: self::C::T%})>;
}
}
constants {
#C1 = constructor-tearoff self::C::•
#C2 = instantiation #C1 <(core::num, {required name: core::String})>
}

View file

@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
: super core::Object::•()
;
method method() → void {
#C2;
#C1<(self::C::T%, {required name: core::String})>;
#C1<(core::num, {required name: self::C::T%})>;
}
}
constants {
#C1 = constructor-tearoff self::C::•
#C2 = instantiation #C1 <(core::num, {required name: core::String})>
}

View file

@ -0,0 +1,3 @@
class C<T> {
void method() {}
}

View file

@ -0,0 +1,3 @@
class C<T> {
void method() {}
}

View file

@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
: super core::Object::•()
;
method method() → void {
#C2;
#C1<(self::C::T%, {required name: core::String})>;
#C1<(core::num, {required name: self::C::T%})>;
}
}
constants {
#C1 = constructor-tearoff self::C::•
#C2 = instantiation #C1 <(core::num*, {required name: core::String*})*>
}

View file

@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
: super core::Object::•()
;
method method() → void {
#C2;
#C1<(self::C::T%, {required name: core::String})>;
#C1<(core::num, {required name: self::C::T%})>;
}
}
constants {
#C1 = constructor-tearoff self::C::•
#C2 = instantiation #C1 <(core::num*, {required name: core::String*})*>
}

View file

@ -0,0 +1,10 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
;
method method() → void
;
}

View file

@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
class C<T extends core::Object? = dynamic> extends core::Object {
synthetic constructor •() → self::C<self::C::T%>
: super core::Object::•()
;
method method() → void {
#C2;
#C1<(self::C::T%, {required name: core::String})>;
#C1<(core::num, {required name: self::C::T%})>;
}
}
constants {
#C1 = constructor-tearoff self::C::•
#C2 = instantiation #C1 <(core::num*, {required name: core::String*})*>
}