Skip to content

Commit c11186b

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[model] Recognize erroneous program encodings in the CFE verifier
For some erroneous programs the CFE produces the code that's not type-safe or valid from the standpoint of a correct program. That should not trigger the verifier warnings though. Change-Id: I78b51ccffb0a74658926728e1a7ee3bf56934fe6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426500 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent a01d47d commit c11186b

File tree

4 files changed

+188
-76
lines changed

4 files changed

+188
-76
lines changed

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ frontends
722722
frozen
723723
fs
724724
fsource
725+
ft
725726
fuchsia
726727
fue
727728
fuller

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,7 @@ unchanged
33093309
unchecked
33103310
unclaimed
33113311
unclear
3312+
unconventional
33123313
undeclared
33133314
undefined
33143315
under

pkg/kernel/lib/naive_type_checker.dart

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ ${superMember} is a ${_memberKind(superMember)}
8282
? ownMember.isCovariantByDeclaration
8383
: ownMember
8484
.function!.positionalParameters[0].isCovariantByDeclaration;
85-
if (!_isValidParameterOverride(
86-
isCovariantByDeclaration, ownType, superType)) {
85+
if (!_isValidParameterOverride(ownType, superType,
86+
isCovariantByDeclaration: isCovariantByDeclaration,
87+
isSuperNoSuchMethodForwarder: superMember is Procedure &&
88+
superMember.isNoSuchMethodForwarder)) {
8789
if (isCovariantByDeclaration) {
8890
return failures.reportInvalidOverride(ownMember, superMember, '''
8991
${ownType} is neither a subtype nor supertype of ${superType}
@@ -203,9 +205,10 @@ ${ownType} is not a subtype of ${superType}
203205
final VariableDeclaration superParameter =
204206
superFunction.positionalParameters[i];
205207
if (!_isValidParameterOverride(
206-
ownParameter.isCovariantByDeclaration,
207208
ownSubstitution.substituteType(ownParameter.type),
208-
superSubstitution.substituteType(superParameter.type))) {
209+
superSubstitution.substituteType(superParameter.type),
210+
isCovariantByDeclaration: ownParameter.isCovariantByDeclaration,
211+
isSuperNoSuchMethodForwarder: superMember.isNoSuchMethodForwarder)) {
209212
return '''
210213
type of parameter ${ownParameter.name} is incompatible
211214
override declares ${ownParameter.type}
@@ -232,9 +235,10 @@ super method declares ${superParameter.type}
232235
}
233236

234237
if (!_isValidParameterOverride(
235-
ownParameter.isCovariantByDeclaration,
236238
ownSubstitution.substituteType(ownParameter.type),
237-
superSubstitution.substituteType(superParameter.type))) {
239+
superSubstitution.substituteType(superParameter.type),
240+
isCovariantByDeclaration: ownParameter.isCovariantByDeclaration,
241+
isSuperNoSuchMethodForwarder: superMember.isNoSuchMethodForwarder)) {
238242
return '''
239243
type of parameter ${ownParameter.name} is incompatible
240244
override declares ${ownParameter.type}
@@ -249,14 +253,27 @@ super method declares ${superParameter.type}
249253
/// Checks whether parameter with [ownParameterType] type is a valid override
250254
/// for parameter with [superParameterType] type taking into account its
251255
/// covariance and applying type parameter [substitution] if necessary.
252-
bool _isValidParameterOverride(bool isCovariantByDeclaration,
253-
DartType ownParameterType, DartType superParameterType) {
256+
bool _isValidParameterOverride(
257+
DartType ownParameterType, DartType superParameterType,
258+
{required bool isCovariantByDeclaration,
259+
required bool isSuperNoSuchMethodForwarder}) {
254260
if (_isSubtypeOf(superParameterType, ownParameterType)) {
255261
return true;
256262
} else if (isCovariantByDeclaration &&
257263
_isSubtypeOf(ownParameterType, superParameterType)) {
258264
return true;
259265
} else {
266+
// In noSuchMethod forwarders some types of parameters are adjusted to be
267+
// nullable. This is a workaround for the backends, and the corresponding
268+
// type mismatch should be ignored by the verifier.
269+
if (isSuperNoSuchMethodForwarder) {
270+
return _isValidParameterOverride(
271+
ownParameterType.withDeclaredNullability(Nullability.nullable),
272+
superParameterType,
273+
isCovariantByDeclaration: isCovariantByDeclaration,
274+
isSuperNoSuchMethodForwarder: false);
275+
}
276+
260277
return false;
261278
}
262279
}

0 commit comments

Comments
 (0)