[cfe] Fix bug where we emit an extra error that we don't want for mixin classes.

Would otherwise emit `CantUseClassAsMixin` and then if the supertype is final or interface, would emit `FinalMixinMixedInOutsideOfLibrary` and `InterfaceMixinMixedInOutsideOfLibrary`respectively. These errors together don't make sense so this CL fixes it.

Change-Id: I5fdf4e260b709e08af53cbda0414cff2ef93d3b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286951
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Kallen Tu 2023-03-07 00:58:22 +00:00 committed by Commit Queue
parent bd42ae8637
commit 3b50e0a921
12 changed files with 502 additions and 3 deletions

View file

@ -2338,9 +2338,7 @@ severity: $severity
.withArguments(mixedInTypeDeclaration.fullNameForErrors),
mixedInTypeBuilder.charOffset ?? TreeNode.noOffset,
noLength);
}
if (cls.libraryBuilder.origin !=
} else if (cls.libraryBuilder.origin !=
mixedInTypeDeclaration.libraryBuilder.origin) {
if (mixedInTypeDeclaration.isInterface &&
!mayIgnoreClassModifiers(mixedInTypeDeclaration)) {

View file

@ -0,0 +1,11 @@
// Copyright (c) 2023, 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.
import 'main_lib.dart';
class BaseWith with BaseClass {}
class InterfaceWith with InterfaceClass {}
class FinalWith with FinalClass {}

View file

@ -0,0 +1,82 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
: super self::_BaseWith&Object&BaseClass::•()
;
}
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
: super self::_InterfaceWith&Object&InterfaceClass::•()
;
}
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
: super self::_FinalWith&Object&FinalClass::•()
;
}
library /*isNonNullableByDefault*/;
import self as mai;
import "dart:core" as core;
base class BaseClass extends core::Object {
synthetic constructor •() → mai::BaseClass
: super core::Object::•()
;
}
interface class InterfaceClass extends core::Object {
synthetic constructor •() → mai::InterfaceClass
: super core::Object::•()
;
}
final class FinalClass extends core::Object {
synthetic constructor •() → mai::FinalClass
: super core::Object::•()
;
}

View file

@ -0,0 +1,82 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass extends core::Object implements mai::BaseClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
: super self::_BaseWith&Object&BaseClass::•()
;
}
abstract class _InterfaceWith&Object&InterfaceClass extends core::Object implements mai::InterfaceClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
: super self::_InterfaceWith&Object&InterfaceClass::•()
;
}
abstract final class _FinalWith&Object&FinalClass extends core::Object implements mai::FinalClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
: super self::_FinalWith&Object&FinalClass::•()
;
}
library /*isNonNullableByDefault*/;
import self as mai;
import "dart:core" as core;
base class BaseClass extends core::Object {
synthetic constructor •() → mai::BaseClass
: super core::Object::•()
;
}
interface class InterfaceClass extends core::Object {
synthetic constructor •() → mai::InterfaceClass
: super core::Object::•()
;
}
final class FinalClass extends core::Object {
synthetic constructor •() → mai::FinalClass
: super core::Object::•()
;
}

View file

@ -0,0 +1,7 @@
import 'main_lib.dart';
class BaseWith with BaseClass {}
class InterfaceWith with InterfaceClass {}
class FinalWith with FinalClass {}

View file

@ -0,0 +1,7 @@
import 'main_lib.dart';
class BaseWith with BaseClass {}
class FinalWith with FinalClass {}
class InterfaceWith with InterfaceClass {}

View file

@ -0,0 +1,82 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
: super self::_BaseWith&Object&BaseClass::•()
;
}
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
: super self::_InterfaceWith&Object&InterfaceClass::•()
;
}
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
: super self::_FinalWith&Object&FinalClass::•()
;
}
library /*isNonNullableByDefault*/;
import self as mai;
import "dart:core" as core;
base class BaseClass extends core::Object {
synthetic constructor •() → mai::BaseClass
: super core::Object::•()
;
}
interface class InterfaceClass extends core::Object {
synthetic constructor •() → mai::InterfaceClass
: super core::Object::•()
;
}
final class FinalClass extends core::Object {
synthetic constructor •() → mai::FinalClass
: super core::Object::•()
;
}

View file

@ -0,0 +1,62 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
: super self::_BaseWith&Object&BaseClass::•()
;
}
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
: super self::_InterfaceWith&Object&InterfaceClass::•()
;
}
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
: super self::_FinalWith&Object&FinalClass::•()
;
}

View file

@ -0,0 +1,76 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
;
}
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
;
}
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
;
}
library /*isNonNullableByDefault*/;
import self as mai;
import "dart:core" as core;
base class BaseClass extends core::Object {
synthetic constructor •() → mai::BaseClass
;
}
interface class InterfaceClass extends core::Object {
synthetic constructor •() → mai::InterfaceClass
;
}
final class FinalClass extends core::Object {
synthetic constructor •() → mai::FinalClass
;
}

View file

@ -0,0 +1,82 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class BaseWith with BaseClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class InterfaceWith with InterfaceClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
// class FinalWith with FinalClass {}
// ^
//
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
// Try adding 'base', 'final', or 'sealed' to the type.
// class FinalWith with FinalClass {}
// ^
//
import self as self;
import "dart:core" as core;
import "main_lib.dart" as mai;
import "org-dartlang-testcase:///main_lib.dart";
abstract final class _BaseWith&Object&BaseClass extends core::Object implements mai::BaseClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
: super core::Object::•()
;
}
class BaseWith extends self::_BaseWith&Object&BaseClass {
synthetic constructor •() → self::BaseWith
: super self::_BaseWith&Object&BaseClass::•()
;
}
abstract class _InterfaceWith&Object&InterfaceClass extends core::Object implements mai::InterfaceClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
: super core::Object::•()
;
}
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
synthetic constructor •() → self::InterfaceWith
: super self::_InterfaceWith&Object&InterfaceClass::•()
;
}
abstract final class _FinalWith&Object&FinalClass extends core::Object implements mai::FinalClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
: super core::Object::•()
;
}
class FinalWith extends self::_FinalWith&Object&FinalClass {
synthetic constructor •() → self::FinalWith
: super self::_FinalWith&Object&FinalClass::•()
;
}
library /*isNonNullableByDefault*/;
import self as mai;
import "dart:core" as core;
base class BaseClass extends core::Object {
synthetic constructor •() → mai::BaseClass
: super core::Object::•()
;
}
interface class InterfaceClass extends core::Object {
synthetic constructor •() → mai::InterfaceClass
: super core::Object::•()
;
}
final class FinalClass extends core::Object {
synthetic constructor •() → mai::FinalClass
: super core::Object::•()
;
}

View file

@ -0,0 +1,9 @@
// Copyright (c) 2023, 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.
base class BaseClass {}
interface class InterfaceClass {}
final class FinalClass {}