-
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.
Fix stack overflow in mixin application from separate library
Make sure that calls to super class methods from mixin application stubs are always generated using `super` and not `this`. Replacing `super` by `this` should not be used as non-virtual field access optimization in forwarding stubs that intend to redirect to the super class members (using `this` redirects to itself and causes infinite recursion). Closes: #50119 Change-Id: Ib9c9aebdc88555518998db64aefa1fd0905c5b11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267822 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Anna Gringauze <[email protected]>
- Loading branch information
Anna Gringauze
authored and
Commit Queue
committed
Nov 4, 2022
1 parent
d4db1e8
commit cc80ccf
Showing
7 changed files
with
213 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2019, 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 'package:expect/expect.dart'; | ||
import 'mixin_declaration.dart'; | ||
|
||
void main() { | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C0().foo); | ||
Expect.equals('B._foo', D0().foo); | ||
|
||
// When mixin application is in a separate library from the declaration, | ||
// private symbol from the current library is used to access `_foo`. | ||
Expect.equals('A._foo', C()._foo); | ||
Expect.equals('A._foo', D()._foo); | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C().foo); | ||
Expect.equals('B._foo', D().foo); | ||
|
||
// E overrides `_foo`. | ||
Expect.equals('E._foo', E()._foo); | ||
} | ||
|
||
class C0 = A0 with B; | ||
class C = A with B; | ||
|
||
class D0 extends A0 with B {} | ||
|
||
class D extends A with B {} | ||
|
||
class E extends A with B { | ||
String? _foo = 'E._foo'; | ||
} | ||
|
||
class A0 {} | ||
|
||
class A { | ||
String? _foo = 'A._foo'; | ||
} |
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 @@ | ||
// Copyright (c) 2019, 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 B { | ||
String? _foo = 'B._foo'; | ||
String get foo => _foo!; | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/dartdevc/mixin/mixin_declaration_application_test.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,44 @@ | ||
// Copyright (c) 2019, 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 'package:expect/expect.dart'; | ||
|
||
void main() { | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C0().foo); | ||
Expect.equals('B._foo', D0().foo); | ||
|
||
// When mixin application is in the same library as the declaration, | ||
// private symbol from the mixin delaration `B._foo` overrides `A._foo`. | ||
Expect.equals('B._foo', C()._foo); | ||
Expect.equals('B._foo', D()._foo); | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C().foo); | ||
Expect.equals('B._foo', D().foo); | ||
|
||
// E overrides `_foo`. | ||
Expect.equals('E._foo', E()._foo); | ||
} | ||
|
||
class C0 = A0 with B; | ||
class C = A with B; | ||
|
||
class D0 extends A0 with B {} | ||
|
||
class D extends A with B {} | ||
|
||
class E extends A with B { | ||
String? _foo = 'E._foo'; | ||
} | ||
|
||
class A0 {} | ||
|
||
class A { | ||
String? _foo = 'A._foo'; | ||
} | ||
|
||
class B { | ||
String? _foo = 'B._foo'; | ||
String get foo => _foo!; | ||
} |
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,42 @@ | ||
// Copyright (c) 2019, 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 'package:expect/expect.dart'; | ||
import 'mixin_declaration.dart'; | ||
|
||
void main() { | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C0().foo); | ||
Expect.equals('B._foo', D0().foo); | ||
|
||
// When mixin application is in a separate library from the declaration, | ||
// private symbol from the current library is used to access `_foo`. | ||
Expect.equals('A._foo', C()._foo); | ||
Expect.equals('A._foo', D()._foo); | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C().foo); | ||
Expect.equals('B._foo', D().foo); | ||
|
||
// E overrides `_foo`. | ||
Expect.equals('E._foo', E()._foo); | ||
} | ||
|
||
class C0 = A0 with B; | ||
class C = A with B; | ||
|
||
class D0 extends A0 with B {} | ||
|
||
class D extends A with B {} | ||
|
||
class E extends A with B { | ||
String _foo = 'E._foo'; | ||
} | ||
|
||
class A0 {} | ||
|
||
class A { | ||
String _foo = 'A._foo'; | ||
} |
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,10 @@ | ||
// Copyright (c) 2019, 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 | ||
|
||
class B { | ||
String _foo = 'B._foo'; | ||
String get foo => _foo; | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/dartdevc_2/mixin/mixin_declaration_application_test.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,46 @@ | ||
// Copyright (c) 2019, 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 'package:expect/expect.dart'; | ||
|
||
void main() { | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C0().foo); | ||
Expect.equals('B._foo', D0().foo); | ||
|
||
// When mixin application is in the same library as the declaration, | ||
// private symbol from the mixin delaration `B._foo` overrides `A._foo`. | ||
Expect.equals('B._foo', C()._foo); | ||
Expect.equals('B._foo', D()._foo); | ||
// Getter `foo` returns `B._foo` that is coming from the mixin declaration. | ||
Expect.equals('B._foo', C().foo); | ||
Expect.equals('B._foo', D().foo); | ||
|
||
// E overrides `_foo`. | ||
Expect.equals('E._foo', E()._foo); | ||
} | ||
|
||
class C0 = A0 with B; | ||
class C = A with B; | ||
|
||
class D0 extends A0 with B {} | ||
|
||
class D extends A with B {} | ||
|
||
class E extends A with B { | ||
String _foo = 'E._foo'; | ||
} | ||
|
||
class A0 {} | ||
|
||
class A { | ||
String _foo = 'A._foo'; | ||
} | ||
|
||
class B { | ||
String _foo = 'B._foo'; | ||
String get foo => _foo; | ||
} |