-
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.
[dart2js] Erase static interop type in static invocation
Static invocations of external factories are casted so that the result, which is a @staticInterop type, can be treated as the erased type instead. This CL fixes the issue where the type that it was casted to was never replaced with the erased type. Change-Id: Ic6eb529349ea2b5c42f91c2740d501d4f81bc38e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323505 Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
6 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
47 changes: 47 additions & 0 deletions
47
tests/lib/js/static_interop_test/generic_factory_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,47 @@ | ||
// 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. | ||
|
||
// Test type parameters on @staticInterop factories. | ||
|
||
import 'package:js/js.dart'; | ||
import 'package:expect/minitest.dart'; | ||
|
||
@JS() | ||
@staticInterop | ||
class Array<T, U extends String> { | ||
external factory Array(T t, U u); | ||
factory Array.nonExternal(T t, U u) => Array(t, u); | ||
} | ||
|
||
extension on Array { | ||
external Object operator [](int index); | ||
} | ||
|
||
@JS() | ||
@staticInterop | ||
@anonymous | ||
class Anonymous<T, U extends String> { | ||
external factory Anonymous({T? t, U? u}); | ||
factory Anonymous.nonExternal({T? t, U? u}) => Anonymous(t: t, u: u); | ||
} | ||
|
||
extension AnonymousExtension<T, U extends String> on Anonymous<T, U> { | ||
external T get t; | ||
external U get u; | ||
} | ||
|
||
void main() { | ||
final arr1 = Array(true, ''); | ||
expect(arr1[0], true); | ||
expect(arr1[1], ''); | ||
final arr2 = Array<bool, String>(false, ''); | ||
expect(arr2[0], false); | ||
expect(arr2[1], ''); | ||
final anon1 = Anonymous(t: true, u: ''); | ||
expect(anon1.t, true); | ||
expect(anon1.u, ''); | ||
final anon2 = Anonymous<bool, String>(t: false, u: ''); | ||
expect(anon2.t, false); | ||
expect(anon2.u, ''); | ||
} |