[cfe] Don't check override for member signatures.

Closes #40460

Change-Id: If418c0c809ec15febfa63c5363f8353cb16fc9de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134521
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2020-02-06 08:59:31 +00:00 committed by commit-bot@chromium.org
parent aadcb4418b
commit 0fe2779149
15 changed files with 466 additions and 7 deletions

View file

@ -0,0 +1,24 @@
// Copyright (c) 2020, 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.
// @dart=2.6
/*library: nnbd=false*/
import 'opt_in.dart';
/*class: LegacyClass:Class,LegacyClass,Object*/
class LegacyClass extends Class {
/*member: LegacyClass.method:int* Function(int*)**/
}
/*class: LegacyInterface:Interface,LegacyInterface,Object*/
abstract class LegacyInterface implements Interface {
/*member: LegacyInterface.method:int* Function(int*)**/
}
/*class: LegacySubClass:Class,Interface,LegacyClass,LegacyInterface,LegacySubClass,Object*/
class LegacySubClass extends LegacyClass implements LegacyInterface {
/*member: LegacySubClass.method:int* Function(int*)**/
}

View file

@ -0,0 +1,17 @@
// Copyright (c) 2020, 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.
/*library: nnbd=true*/
/*class: Class:Class,Object*/
class Class {
/*member: Class.method:int! Function(int?)!*/
int method(int? i) => i ?? 0;
}
/*class: Interface:Interface,Object*/
abstract class Interface {
/*member: Interface.method:int? Function(int!)!*/
int? method(int i);
}

View file

@ -0,0 +1,25 @@
// Copyright (c) 2020, 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.
/*library: nnbd=false*/
// @dart=2.6
import 'opt_in.dart';
/*class: B2:A,B2,C2,Object*/
abstract class B2 extends A implements C2 {
/*member: B2.method:int* Function(int*,{dynamic optional})**/
/*member: B2.noSuchMethod:dynamic Function(Invocation*)**/
noSuchMethod(Invocation invocation) {
return super.noSuchMethod(invocation);
}
}
/*class: C2:C2,Object*/
abstract class C2 {
/*member: C2.method:int* Function(int*,{dynamic optional})**/
int method(int i, {optional});
}

View file

@ -0,0 +1,27 @@
// Copyright (c) 2020, 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.
/*library: nnbd=true*/
/*class: A:A,Object*/
class A {
/*member: A.method:int! Function(int?)!*/
int method(int? i) => i ?? 0;
}
/*class: B1:A,B1,C1,Object*/
abstract class B1 extends A implements C1 {
/*member: B1.method:int! Function(int?,{dynamic optional})!*/
/*member: B1.noSuchMethod:dynamic Function(Invocation!)!*/
noSuchMethod(Invocation invocation) {
return super.noSuchMethod(invocation);
}
}
/*class: C1:C1,Object*/
abstract class C1 {
/*member: C1.method:int! Function(int?,{dynamic optional})!*/
int method(int? i, {optional});
}

View file

@ -14,6 +14,10 @@ class Object {
const Object();
bool operator ==(Object other) => true;
noSuchMethod(Invocation invocation) => null;
String toString() => '';
}
/*class: Null:Null,Object*/
@ -61,3 +65,6 @@ class Symbol {}
/*class: Type:Object,Type*/
class Type {}
/*class: Invocation:Invocation,Object*/
class Invocation {}

View file

@ -8,38 +8,77 @@
/*class: Class1:Class1,Object*/
class Class1 {
/*member: Class1.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class1.toString:String* Function()**/
/*member: Class1.==:bool! Function(dynamic)**/
operator ==(other) => true;
}
/*class: Class2a:Class2a,Object*/
abstract class Class2a {
/*member: Class2a.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class2a.toString:String* Function()**/
/*member: Class2a.==:bool* Function(Object*)**/
bool operator ==(Object other);
}
/*class: Class2b:Class2a,Class2b,Object*/
class Class2b extends Class2a {
/*member: Class2b.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class2b.toString:String* Function()**/
/*member: Class2b.==:bool* Function(Object*)**/
}
/*class: Class3a:Class3a,Object*/
class Class3a {
/*member: Class3a.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class3a.toString:String* Function()**/
/*member: Class3a.==:bool* Function(Object*)**/
}
/*class: Class3b:Class3a,Class3b,Object*/
abstract class Class3b extends Class3a {
/*member: Class3b.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class3b.toString:String* Function()**/
/*member: Class3b.==:bool* Function(Object*)**/
bool operator ==(Object other);
}
/*class: Class3c:Class3a,Class3b,Class3c,Object*/
class Class3c extends Class3b {
/*member: Class3c.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Class3c.toString:String* Function()**/
/*member: Class3c.==:bool* Function(Object*)**/
}
/*class: Foo:Foo,Object*/
class Foo extends /*error: TypeNotFound*/ Unresolved {
/*member: Foo.noSuchMethod:dynamic Function(Invocation*)**/
/*member: Foo.toString:String* Function()**/
/*member: Foo.==:bool* Function(Object*)**/
}
/*class: A:A,Object*/
abstract class A {
/*member: A.noSuchMethod:dynamic Function(Invocation*)**/
/*member: A.==:bool* Function(Object*)**/
/*member: A.toString:String* Function({bool* withNullability})**/
String toString({bool withNullability = false}) {
return '';
}
}
/*class: B:A,B,Object*/
abstract class B implements A {
/*member: B.toString:String* Function({bool* withNullability})**/
/*member: B.==:bool* Function(Object*)**/
/*member: B.noSuchMethod:dynamic Function(Invocation*)**/
noSuchMethod(Invocation invocation) {
return super.noSuchMethod(invocation);
}
}

View file

@ -551,8 +551,10 @@ class ClassHierarchyNodeBuilder {
debug?.log("supertypes: checkValidOverride("
"${classBuilder.fullNameForErrors}, "
"${fullName(a)}, ${fullName(b)})");
checkValidOverride(a, b);
if (a is DelayedMember && !a.isInheritableConflict) {
if (a is! DelayedMember) {
checkValidOverride(a, b);
}
if (a is DelayedMember) {
if (b is DelayedMember) {
b.addAllDeclarationsTo(a.declarations);
} else {
@ -2432,7 +2434,7 @@ class InheritedImplementationInterfaceConflict extends DelayedMember {
return parent == this.classBuilder
? this
: new InheritedImplementationInterfaceConflict(
parent, declarations, isSetter, modifyKernel);
parent, declarations.toList(), isSetter, modifyKernel);
}
static ClassMember combined(
@ -2497,9 +2499,13 @@ class InterfaceConflict extends DelayedMember {
unhandled("${member.runtimeType}", "$member", classBuilder.charOffset,
classBuilder.fileUri);
}
return Substitution.fromInterfaceType(hierarchy.getKernelTypeAsInstanceOf(
thisType, member.enclosingClass, classBuilder.library.library))
.substituteType(type);
InterfaceType instance = hierarchy.getKernelTypeAsInstanceOf(
thisType, member.enclosingClass, classBuilder.library.library);
assert(
instance != null,
"No instance of $thisType as ${member.enclosingClass} found for "
"$member.");
return Substitution.fromInterfaceType(instance).substituteType(type);
}
bool isMoreSpecific(ClassHierarchyBuilder hierarchy, DartType a, DartType b) {
@ -2628,7 +2634,8 @@ class InterfaceConflict extends DelayedMember {
DelayedMember withParent(ClassBuilder parent) {
return parent == this.classBuilder
? this
: new InterfaceConflict(parent, declarations, isSetter, modifyKernel);
: new InterfaceConflict(
parent, declarations.toList(), isSetter, modifyKernel);
}
static ClassMember combined(ClassBuilder parent, ClassMember a, ClassMember b,

View file

@ -0,0 +1,20 @@
// Copyright (c) 2020, 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.
// @dart=2.6
import 'nsm_from_opt_in_lib.dart';
abstract class B2 extends A implements C2 {
@override
noSuchMethod(Invocation invocation) {
return super.noSuchMethod(invocation);
}
}
abstract class C2 {
int method(int i, {optional});
}
main() {}

View file

@ -0,0 +1,46 @@
library;
import self as self;
import "nsm_from_opt_in_lib.dart" as nsm;
import "dart:core" as core;
import "org-dartlang-testcase:///nsm_from_opt_in_lib.dart";
abstract class B2 extends nsm::A implements self::C2 {
synthetic constructor •() → self::B2*
;
@core::override
method noSuchMethod(core::Invocation* invocation) → dynamic
;
abstract forwarding-stub method method(core::int* i, {dynamic optional}) → core::int*;
}
abstract class C2 extends core::Object {
synthetic constructor •() → self::C2*
;
abstract method method(core::int* i, {dynamic optional}) → core::int*;
}
static method main() → dynamic
;
library;
import self as nsm;
import "dart:core" as core;
class A extends core::Object {
synthetic constructor •() → nsm::A
;
method method(core::int? i) → core::int
;
}
abstract class B1 extends nsm::A implements nsm::C1 {
synthetic constructor •() → nsm::B1
;
@core::override
method noSuchMethod(core::Invocation invocation) → dynamic
;
abstract forwarding-stub method method(core::int? i, {dynamic optional}) → core::int;
}
abstract class C1 extends core::Object {
synthetic constructor •() → nsm::C1
;
abstract method method(core::int? i, {dynamic optional}) → core::int;
}

View file

@ -0,0 +1,57 @@
library;
import self as self;
import "nsm_from_opt_in_lib.dart" as nsm;
import "dart:core" as core;
import "org-dartlang-testcase:///nsm_from_opt_in_lib.dart";
abstract class B2 extends nsm::A implements self::C2 {
synthetic constructor •() → self::B2*
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation* invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
abstract class C2 extends core::Object {
synthetic constructor •() → self::C2*
: super core::Object::•()
;
abstract method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
static method main() → dynamic {}
library;
import self as nsm;
import "dart:core" as core;
class A extends core::Object {
synthetic constructor •() → nsm::A
: super core::Object::•()
;
method method(core::int? i) → core::int
return let final core::int? #t1 = i in #t1.{core::num::==}(null) ?{core::int} 0 : #t1{core::int};
}
abstract class B1 extends nsm::A implements nsm::C1 {
synthetic constructor •() → nsm::B1
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
abstract class C1 extends core::Object {
synthetic constructor •() → nsm::C1
: super core::Object::•()
;
abstract method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
constants {
#C1 = core::_Override {}
#C2 = null
}

View file

@ -0,0 +1,57 @@
library;
import self as self;
import "nsm_from_opt_in_lib.dart" as nsm;
import "dart:core" as core;
import "org-dartlang-testcase:///nsm_from_opt_in_lib.dart";
abstract class B2 extends nsm::A implements self::C2 {
synthetic constructor •() → self::B2*
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation* invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
abstract class C2 extends core::Object {
synthetic constructor •() → self::C2*
: super core::Object::•()
;
abstract method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
static method main() → dynamic {}
library;
import self as nsm;
import "dart:core" as core;
class A extends core::Object {
synthetic constructor •() → nsm::A
: super core::Object::•()
;
method method(core::int? i) → core::int
return let final core::int? #t1 = i in #t1.{core::num::==}(null) ?{core::int} 0 : #t1{core::int};
}
abstract class B1 extends nsm::A implements nsm::C1 {
synthetic constructor •() → nsm::B1
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
abstract class C1 extends core::Object {
synthetic constructor •() → nsm::C1
: super core::Object::•()
;
abstract method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
constants {
#C1 = core::_Override {}
#C2 = null
}

View file

@ -0,0 +1,57 @@
library;
import self as self;
import "nsm_from_opt_in_lib.dart" as nsm;
import "dart:core" as core;
import "org-dartlang-testcase:///nsm_from_opt_in_lib.dart";
abstract class B2 extends nsm::A implements self::C2 {
synthetic constructor •() → self::B2*
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation* invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
abstract class C2 extends core::Object {
synthetic constructor •() → self::C2*
: super core::Object::•()
;
abstract method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
static method main() → dynamic {}
library;
import self as nsm;
import "dart:core" as core;
class A extends core::Object {
synthetic constructor •() → nsm::A
: super core::Object::•()
;
method method(core::int? i) → core::int
return let final core::int? #t1 = i in #t1.{core::num::==}(null) ?{core::int} 0 : #t1{core::int};
}
abstract class B1 extends nsm::A implements nsm::C1 {
synthetic constructor •() → nsm::B1
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
abstract class C1 extends core::Object {
synthetic constructor •() → nsm::C1
: super core::Object::•()
;
abstract method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
constants {
#C1 = core::_Override {}
#C2 = null
}

View file

@ -0,0 +1,57 @@
library;
import self as self;
import "nsm_from_opt_in_lib.dart" as nsm;
import "dart:core" as core;
import "org-dartlang-testcase:///nsm_from_opt_in_lib.dart";
abstract class B2 extends nsm::A implements self::C2 {
synthetic constructor •() → self::B2*
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation* invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
abstract class C2 extends core::Object {
synthetic constructor •() → self::C2*
: super core::Object::•()
;
abstract method method(core::int* i, {dynamic optional = #C2}) → core::int*;
}
static method main() → dynamic {}
library;
import self as nsm;
import "dart:core" as core;
class A extends core::Object {
synthetic constructor •() → nsm::A
: super core::Object::•()
;
method method(core::int? i) → core::int
return let final core::int? #t1 = i in #t1.{core::num::==}(null) ?{core::int} 0 : #t1{core::int};
}
abstract class B1 extends nsm::A implements nsm::C1 {
synthetic constructor •() → nsm::B1
: super nsm::A::•()
;
@#C1
method noSuchMethod(core::Invocation invocation) → dynamic {
return super.{core::Object::noSuchMethod}(invocation);
}
abstract forwarding-stub method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
abstract class C1 extends core::Object {
synthetic constructor •() → nsm::C1
: super core::Object::•()
;
abstract method method(core::int? i, {dynamic optional = #C2}) → core::int;
}
constants {
#C1 = core::_Override {}
#C2 = null
}

View file

@ -0,0 +1,18 @@
// Copyright (c) 2020, 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 A {
int method(int? i) => i ?? 0;
}
abstract class B1 extends A implements C1 {
@override
noSuchMethod(Invocation invocation) {
return super.noSuchMethod(invocation);
}
}
abstract class C1 {
int method(int? i, {optional});
}

View file

@ -1248,6 +1248,7 @@ nnbd/no_null_shorting: TextSerializationFailure
nnbd/no_null_shorting_explicit_extension: TextSerializationFailure
nnbd/no_null_shorting_extension: TextSerializationFailure
nnbd/non_nullable_field_initialization: TextSerializationFailure
nnbd/nsm_from_opt_in: TextSerializationFailure
nnbd/null_access: TextSerializationFailure
nnbd/null_aware_chain: TextSerializationFailure
nnbd/null_check: TextSerializationFailure