-
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 super-bounded aliased constructor invocations
This CL also threads through the inferredness of type arguments for the factories, so that the error that is checked twice isn't reported twice because the arguments are recognized as inferred in one place and as explicit in the other. Closes #42446. Bug: #42446 Change-Id: I8cc158b6d8070d34c1489386962fa1f5e2592719 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184270 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
- Loading branch information
Dmitry Stefantsov
authored and
commit-bot@chromium.org
committed
Feb 15, 2021
1 parent
774b80f
commit b994d51
Showing
9 changed files
with
208 additions
and
32 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
20 changes: 20 additions & 0 deletions
20
pkg/front_end/testcases/nonfunction_type_aliases/issue42446.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,20 @@ | ||
// Copyright (c) 2021, 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<X extends A<X>> {} | ||
typedef B<X extends A<X>> = A<X>; | ||
|
||
class A2<X extends A2<X>> { | ||
factory A2() => throw 42; | ||
} | ||
typedef B2<X extends A2<X>> = A2<X>; | ||
|
||
foo() { | ||
B(); // Error. | ||
A(); // Error. | ||
B2(); // Error. | ||
A2(); // Error. | ||
} | ||
|
||
main() {} |
8 changes: 8 additions & 0 deletions
8
pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart.textual_outline.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,8 @@ | ||
class A<X extends A<X>> {} | ||
typedef B<X extends A<X>> = A<X>; | ||
class A2<X extends A2<X>> { | ||
factory A2() => throw 42; | ||
} | ||
typedef B2<X extends A2<X>> = A2<X>; | ||
foo() {} | ||
main() {} |
65 changes: 65 additions & 0 deletions
65
pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart.weak.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,65 @@ | ||
library /*isNonNullableByDefault*/; | ||
// | ||
// Problems in library: | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:14:3: Error: Inferred type argument 'A<Object?>' doesn't conform to the bound 'A<X>' of the type variable 'X' on 'A'. | ||
// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// B(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:5:9: Context: This is the type variable whose bound isn't conformed to. | ||
// class A<X extends A<X>> {} | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:15:3: Error: Inferred type argument 'A<Object?>' doesn't conform to the bound 'A<X>' of the type variable 'X' on 'A'. | ||
// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// A(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:5:9: Context: This is the type variable whose bound isn't conformed to. | ||
// class A<X extends A<X>> {} | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:16:3: Error: Inferred type argument 'A2<Object?>' doesn't conform to the bound 'A2<X>' of the type variable 'X' on 'A2'. | ||
// - 'A2' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// B2(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:8:10: Context: This is the type variable whose bound isn't conformed to. | ||
// class A2<X extends A2<X>> { | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:17:3: Error: Inferred type argument 'A2<Object?>' doesn't conform to the bound 'A2<X>' of the type variable 'X' on 'A2'. | ||
// - 'A2' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// A2(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:8:10: Context: This is the type variable whose bound isn't conformed to. | ||
// class A2<X extends A2<X>> { | ||
// ^ | ||
// | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
typedef B<X extends self::A<X> = self::A<dynamic>> = self::A<X>; | ||
typedef B2<X extends self::A2<X> = self::A2<dynamic>> = self::A2<X>; | ||
class A<X extends self::A<self::A::X> = self::A<dynamic>> extends core::Object { | ||
synthetic constructor •() → self::A<self::A::X> | ||
: super core::Object::•() | ||
; | ||
} | ||
class A2<X extends self::A2<self::A2::X> = self::A2<dynamic>> extends core::Object { | ||
static factory •<X extends self::A2<self::A2::•::X> = self::A2<dynamic>>() → self::A2<self::A2::•::X> | ||
return throw 42; | ||
} | ||
static method foo() → dynamic { | ||
new self::A::•<self::A<core::Object?>>(); | ||
new self::A::•<self::A<core::Object?>>(); | ||
self::A2::•<self::A2<core::Object?>>(); | ||
self::A2::•<self::A2<core::Object?>>(); | ||
} | ||
static method main() → dynamic {} |
65 changes: 65 additions & 0 deletions
65
pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart.weak.transformed.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,65 @@ | ||
library /*isNonNullableByDefault*/; | ||
// | ||
// Problems in library: | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:14:3: Error: Inferred type argument 'A<Object?>' doesn't conform to the bound 'A<X>' of the type variable 'X' on 'A'. | ||
// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// B(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:5:9: Context: This is the type variable whose bound isn't conformed to. | ||
// class A<X extends A<X>> {} | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:15:3: Error: Inferred type argument 'A<Object?>' doesn't conform to the bound 'A<X>' of the type variable 'X' on 'A'. | ||
// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// A(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:5:9: Context: This is the type variable whose bound isn't conformed to. | ||
// class A<X extends A<X>> {} | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:16:3: Error: Inferred type argument 'A2<Object?>' doesn't conform to the bound 'A2<X>' of the type variable 'X' on 'A2'. | ||
// - 'A2' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// B2(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:8:10: Context: This is the type variable whose bound isn't conformed to. | ||
// class A2<X extends A2<X>> { | ||
// ^ | ||
// | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:17:3: Error: Inferred type argument 'A2<Object?>' doesn't conform to the bound 'A2<X>' of the type variable 'X' on 'A2'. | ||
// - 'A2' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart'. | ||
// - 'Object' is from 'dart:core'. | ||
// Try specifying type arguments explicitly so that they conform to the bounds. | ||
// A2(); // Error. | ||
// ^ | ||
// pkg/front_end/testcases/nonfunction_type_aliases/issue42446.dart:8:10: Context: This is the type variable whose bound isn't conformed to. | ||
// class A2<X extends A2<X>> { | ||
// ^ | ||
// | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
typedef B<X extends self::A<X> = self::A<dynamic>> = self::A<X>; | ||
typedef B2<X extends self::A2<X> = self::A2<dynamic>> = self::A2<X>; | ||
class A<X extends self::A<self::A::X> = self::A<dynamic>> extends core::Object { | ||
synthetic constructor •() → self::A<self::A::X> | ||
: super core::Object::•() | ||
; | ||
} | ||
class A2<X extends self::A2<self::A2::X> = self::A2<dynamic>> extends core::Object { | ||
static factory •<X extends self::A2<self::A2::•::X> = self::A2<dynamic>>() → self::A2<self::A2::•::X> | ||
return throw 42; | ||
} | ||
static method foo() → dynamic { | ||
new self::A::•<self::A<core::Object?>>(); | ||
new self::A::•<self::A<core::Object?>>(); | ||
self::A2::•<self::A2<core::Object?>>(); | ||
self::A2::•<self::A2<core::Object?>>(); | ||
} | ||
static method main() → dynamic {} |
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