Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LanguageFeatures/Private-fields-promotion/not_promotable_A01_t04 has incorrect expectation #2306

Closed
stereotype441 opened this issue Oct 12, 2023 · 0 comments
Assignees
Labels
bad-test Report tests in need of updates. When closed, the tests should be considered good

Comments

@stereotype441
Copy link
Member

LanguageFeatures/Private-fields-promotion/not_promotable_A01_t04 looks like this:

class A {
  void foo() {}
}

class C<T> {
   external final T _x;

  void test() {
    if (_x is A) {
      _x.foo();
//       ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
    }
  }
}

main() {
  C c = C();
  if (c._x is A) {
    c._x.foo();
//       ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }
  c.test();
}

The test is trying to verify that C._x does not type promote.

The first expectation (inside C.test) works fine, because inside an instance method of C, the unpromoted type of _x is T, and therefore trying to call _x.foo() is an effective way of verifying that _x wasn't promoted to A.

The second expectation (inside main) is problematic, because C c = C(); gets type inferred as C<dynamic> c = C();, therefore the unpromoted type of c._x is dynamic, and so the call to c._x.foo() works regardless of whether c._x has been type promoted.

One possible fix would be to change the first line of main to var c = C<Object>(). That would ensure that the unpromoted type of c._x is Object, and so the call to c._x.foo() would be an effective way of verifying that c._x hasn't been type promoted.

@sgrekhov sgrekhov added the bad-test Report tests in need of updates. When closed, the tests should be considered good label Oct 13, 2023
sgrekhov added a commit to sgrekhov/co19 that referenced this issue Oct 13, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Oct 15, 2023
2023-10-13 [email protected] Fixes dart-lang/co19#2310. Fix new roll failures (dart-lang/co19#2311)
2023-10-13 [email protected] Fixes dart-lang/co19#2306. Fix promoted instance type in not_promotable_A01_t04.dart (dart-lang/co19#2309)
2023-10-13 [email protected] Fixes dart-lang/co19#2307. Don't expect private fields promotion on static fields (dart-lang/co19#2308)
2023-10-11 [email protected] dart-lang/co19#2291. Update `Link.create()` tests according to the documentation (dart-lang/co19#2299)
2023-10-11 [email protected] dart-lang/co19#2275. Add `noSuchMethod` tests. Part 3 (dart-lang/co19#2294)
2023-10-10 [email protected] dart-lang/co19#2275. Add `noSuchMethod` tests. Part 4 (dynamic semantics) (dart-lang/co19#2296)
2023-10-10 [email protected] dart-lang/co19#2291. Update `Link.create()` according to the documentation. Part 2 (dart-lang/co19#2301)
2023-10-10 [email protected] Fixes dart-lang/co19#2268. Fix LibTest/io/WebSocket/closeCode_A01_t02.dart to be not racy (dart-lang/co19#2302)
2023-10-09 [email protected] dart-lang/co19#1400. Add more tests for private fields promotion of extension types (dart-lang/co19#2300)

Change-Id: Ib34f392c8a2a0aaab8b7b0cb028f918ab2a3249f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330460
Commit-Queue: Alexander Thomas <[email protected]>
Reviewed-by: Erik Ernst <[email protected]>
Reviewed-by: Alexander Thomas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bad-test Report tests in need of updates. When closed, the tests should be considered good
Projects
None yet
Development

No branches or pull requests

2 participants