-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfe] Disallow implementing a legacy library subclass of a final/base…
… class in the core libraries. This behaviour should only happen when a post-feature library implements a pre-feature library declaration that has a final/base core library class as a super declaration. Bug: #52115 Change-Id: If42129ba3ba7e337cc6ffc21604c6d0f2976344c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301503 Reviewed-by: Nate Bosch <[email protected]> Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
- Loading branch information
Showing
29 changed files
with
699 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
pkg/front_end/testcases/class_modifiers/issue52115/main.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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 'dart:collection'; | ||
import "main_lib.dart"; | ||
|
||
// Implementing a legacy class that implements a core library base class. | ||
abstract base class LegacyImplementBase<E extends LinkedListEntry<E>> | ||
implements LegacyImplementBaseCore<E> {} | ||
|
||
// Implementing a legacy class that implements a core library final class. | ||
final class LegacyImplementFinal implements LegacyImplementFinalCore { | ||
int get key => 0; | ||
int get value => 1; | ||
String toString() => "Bad"; | ||
} |
66 changes: 66 additions & 0 deletions
66
pkg/front_end/testcases/class_modifiers/issue52115/main.dart.strong.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
library /*isNonNullableByDefault*/; | ||
// | ||
// Problems in library: | ||
// | ||
// pkg/front_end/testcases/class_modifiers/issue52115/main.dart:10:16: Error: The class 'LinkedList' can't be implemented outside of its library because it's a base class. | ||
// implements LegacyImplementBaseCore<E> {} | ||
// ^ | ||
// sdk/lib/collection/linked_list.dart:81:12: Context: The type 'LegacyImplementBaseCore' is a subtype of 'LinkedList', and 'LinkedList' is defined here. | ||
// base class LinkedList<E extends LinkedListEntry<E>> extends Iterable<E> { | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/class_modifiers/issue52115/main.dart:13:45: Error: The class 'MapEntry' can't be implemented outside of its library because it's a final class. | ||
// final class LegacyImplementFinal implements LegacyImplementFinalCore { | ||
// ^ | ||
// sdk/lib/core/map.dart:472:13: Context: The type 'LegacyImplementFinalCore' is a subtype of 'MapEntry', and 'MapEntry' is defined here. | ||
// final class MapEntry<K, V> { | ||
// ^ | ||
// | ||
import self as self; | ||
import "dart:collection" as col; | ||
import "dart:core" as core; | ||
import "main_lib.dart" as mai; | ||
|
||
import "dart:collection"; | ||
import "org-dartlang-testcase:///main_lib.dart"; | ||
|
||
abstract base class LegacyImplementBase<E extends col::LinkedListEntry<self::LegacyImplementBase::E> = col::LinkedListEntry<dynamic>> extends core::Object implements mai::LegacyImplementBaseCore<self::LegacyImplementBase::E> { | ||
synthetic constructor •() → self::LegacyImplementBase<self::LegacyImplementBase::E> | ||
: super core::Object::•() | ||
; | ||
} | ||
final class LegacyImplementFinal extends core::Object implements mai::LegacyImplementFinalCore { | ||
synthetic constructor •() → self::LegacyImplementFinal | ||
: super core::Object::•() | ||
; | ||
get key() → core::int | ||
return 0; | ||
get value() → core::int | ||
return 1; | ||
method toString() → core::String | ||
return "Bad"; | ||
} | ||
|
||
library /*isNonNullableByDefault*/; | ||
import self as mai; | ||
import "dart:collection" as col; | ||
import "dart:core" as core; | ||
|
||
import "dart:collection"; | ||
|
||
abstract class LegacyImplementBaseCore<E extends col::LinkedListEntry<mai::LegacyImplementBaseCore::E> = col::LinkedListEntry<dynamic>> extends core::Object implements col::LinkedList<mai::LegacyImplementBaseCore::E> { | ||
synthetic constructor •() → mai::LegacyImplementBaseCore<mai::LegacyImplementBaseCore::E> | ||
: super core::Object::•() | ||
; | ||
} | ||
class LegacyImplementFinalCore extends core::Object implements core::MapEntry<core::int, core::int> { | ||
synthetic constructor •() → mai::LegacyImplementFinalCore | ||
: super core::Object::•() | ||
; | ||
get key() → core::int | ||
return 0; | ||
get value() → core::int | ||
return 1; | ||
method toString() → core::String | ||
return "Bad"; | ||
} |
Oops, something went wrong.