mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
[cfe] Handle mixing in Function
Closes #35477 Closes #35573 Change-Id: I0612641108caf1fa08da1aae7684e7f33dfe3b46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140402 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
2049335af3
commit
0e75a0650f
|
@ -12,8 +12,13 @@ class A implements Function {}
|
|||
/*analyzer.class: B:B,Function,Object*/
|
||||
class B extends Function {}
|
||||
|
||||
/*class: C:C,Function,Object*/
|
||||
class C extends Object with Function {
|
||||
/*cfe|cfe:builder.member: C.hashCode:int**/
|
||||
/*cfe|cfe:builder.member: C.==:bool* Function(Object*)**/
|
||||
}
|
||||
/*cfe|cfe:builder.class: C:C,Object,_C&Object&Function*/
|
||||
/*analyzer.class: C:C,Function,Object*/
|
||||
class C extends Object with Function {}
|
||||
|
||||
// CFE hides that this is a mixin declaration since its mixed in type has been
|
||||
// removed.
|
||||
/*cfe|cfe:builder.class: _C&Object&Function:Object,_C&Object&Function*/
|
||||
|
||||
/*cfe|cfe:builder.class: D:D,Object*/
|
||||
class D = Object with Function;
|
||||
|
|
|
@ -77,6 +77,7 @@ import '../fasta_codes.dart'
|
|||
noLength,
|
||||
messageExtendFunction,
|
||||
messageImplementFunction,
|
||||
messageMixinFunction,
|
||||
templateConflictsWithConstructor,
|
||||
templateConflictsWithFactory,
|
||||
templateConflictsWithMember,
|
||||
|
@ -245,13 +246,24 @@ class SourceClassBuilder extends ClassBuilderImpl
|
|||
actualCls.supertype = supertype;
|
||||
|
||||
mixedInTypeBuilder = checkSupertype(mixedInTypeBuilder);
|
||||
actualCls.mixedInType =
|
||||
Supertype mixedInType =
|
||||
mixedInTypeBuilder?.buildMixedInType(library, charOffset, fileUri);
|
||||
if (actualCls.mixedInType == null &&
|
||||
mixedInTypeBuilder is! NamedTypeBuilder) {
|
||||
if (mixedInType != null) {
|
||||
Class superclass = mixedInType.classNode;
|
||||
if (superclass.name == 'Function' &&
|
||||
superclass.enclosingLibrary == coreLibrary.library) {
|
||||
library.addProblem(messageMixinFunction, charOffset, noLength, fileUri);
|
||||
mixedInType = null;
|
||||
mixedInTypeBuilder = null;
|
||||
actualCls.isAnonymousMixin = false;
|
||||
isMixinDeclaration = false;
|
||||
}
|
||||
}
|
||||
if (mixedInType == null && mixedInTypeBuilder is! NamedTypeBuilder) {
|
||||
mixedInTypeBuilder = null;
|
||||
}
|
||||
actualCls.isMixinDeclaration = isMixinDeclaration;
|
||||
actualCls.mixedInType = mixedInType;
|
||||
|
||||
// TODO(ahe): If `cls.supertype` is null, and this isn't Object, report a
|
||||
// compile-time error.
|
||||
|
|
|
@ -459,7 +459,7 @@ MissingPartOf/part_wrapped_script: Fail # Using 'part' in the (now) part.
|
|||
MissingPrefixInDeferredImport/example: Fail
|
||||
MixinDeclaresConstructor/example: Fail
|
||||
MixinFunction/part_wrapped_script: Fail
|
||||
MixinFunction/script: Fail # TODO(johnniwinther): Handle mixing in Function
|
||||
MixinFunction/script: Fail # TODO(johnniwinther): This message is currently ignored.
|
||||
MixinInferenceNoMatchingClass/example: Fail
|
||||
ModifierOutOfOrder/part_wrapped_script1: Fail
|
||||
ModifierOutOfOrder/script1: Fail
|
||||
|
|
13
pkg/front_end/testcases/general/inherit_function.dart
Normal file
13
pkg/front_end/testcases/general/inherit_function.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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 implements Function {}
|
||||
|
||||
class B extends Function {}
|
||||
|
||||
class C extends Object with Function {}
|
||||
|
||||
class D = Object with Function;
|
||||
|
||||
main() {}
|
|
@ -0,0 +1,26 @@
|
|||
library;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class A extends core::Object {
|
||||
synthetic constructor •() → self::A*
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
synthetic constructor •() → self::B*
|
||||
;
|
||||
}
|
||||
abstract class _C&Object&Function extends core::Object {
|
||||
synthetic constructor •() → self::_C&Object&Function*
|
||||
;
|
||||
}
|
||||
class C extends self::_C&Object&Function {
|
||||
synthetic constructor •() → self::C*
|
||||
;
|
||||
}
|
||||
class D extends core::Object {
|
||||
synthetic constructor •() → self::D*
|
||||
;
|
||||
}
|
||||
static method main() → dynamic
|
||||
;
|
|
@ -0,0 +1,30 @@
|
|||
library;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class A extends core::Object {
|
||||
synthetic constructor •() → self::A*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
synthetic constructor •() → self::B*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
abstract class _C&Object&Function extends core::Object {
|
||||
synthetic constructor •() → self::_C&Object&Function*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
class C extends self::_C&Object&Function {
|
||||
synthetic constructor •() → self::C*
|
||||
: super self::_C&Object&Function::•()
|
||||
;
|
||||
}
|
||||
class D extends core::Object {
|
||||
synthetic constructor •() → self::D*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method main() → dynamic {}
|
|
@ -0,0 +1,30 @@
|
|||
library;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class A extends core::Object {
|
||||
synthetic constructor •() → self::A*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
synthetic constructor •() → self::B*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
abstract class _C&Object&Function extends core::Object {
|
||||
synthetic constructor •() → self::_C&Object&Function*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
class C extends self::_C&Object&Function {
|
||||
synthetic constructor •() → self::C*
|
||||
: super self::_C&Object&Function::•()
|
||||
;
|
||||
}
|
||||
class D extends core::Object {
|
||||
synthetic constructor •() → self::D*
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method main() → dynamic {}
|
|
@ -218,6 +218,7 @@ general/infer_field_from_multiple: TypeCheckError
|
|||
general/infer_field_type: TextSerializationFailure
|
||||
general/infer_fixed_generic_return_type: TextSerializationFailure
|
||||
general/infer_map_literal_with_closure: TextSerializationFailure
|
||||
general/inherit_function: TextSerializationFailure
|
||||
general/interface_conflict: TextSerializationFailure
|
||||
general/interface_contravariant_from_class: TextSerializationFailure
|
||||
general/interface_covariantImpl_from_class: TextSerializationFailure
|
||||
|
|
Loading…
Reference in a new issue