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

Fixes #2059. Don't expect an error in a weak mode #2060

Merged
merged 1 commit into from
May 23, 2023

Conversation

sgrekhov
Copy link
Contributor

This test used to test a strong mode. Now in a weak mode it fails. As far as I understand here we have class

class C<T> {
  final T x;
  const C.t(Object? o, T t) : x = o as T;
}

When we call

const c1 = C.t(null, cLegacyInt);

T is inferred as int*. int* became int and x = o as int; failed. But now in a weak mode is doesn't throw, so we should expect no error

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, after a bit of thinking.

@@ -11,19 +11,15 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github won't let me comment on earlier lines, but I think CONST_CANONICAL_TYPE(int*) is int*. (CONST_CANONICAL_TYPE adds the * on almost every type (the only exception I can easily spot is that CONST_CANONICAL_TYPE(T?) is T2? for some T2).

However, I don't think this matters for the source code below.

@@ -11,19 +11,15 @@

// Requirements=nnbd-weak

import "../../../Utils/expect.dart";
import '../const_evaluation_lib.dart';
import 'const_evaluation_legacy_lib.dart';

const dynamic d = null;

main() {
const c1 = C.t(null, cLegacyInt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tricky as usual. ;-)

The inferred type argument for C needs to be a supertype of Null and a supertype of int* (the type of cLegacyInt), but there are several types satisfying this. So we shouldn't have a compile-time error.

Next, no-sound-null-safety execution will not throw when o as T is tested in a situation where o evaluates to null. So we should indeed expect that there is no run-time error.

Very good, should work!

@eernstg eernstg merged commit 29c7947 into dart-lang:master May 23, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request May 24, 2023
2023-05-24 sgrekhov22@gmail.com Fixes dart-lang/co19#2061. Add expected analyzer error (dart-lang/co19#2062)
2023-05-23 sgrekhov22@gmail.com Fixes dart-lang/co19#2059. Don't expect an error in a weak mode (dart-lang/co19#2060)
2023-05-23 sgrekhov22@gmail.com Fixes dart-lang/co19#2056. Make const_evaluation_A06_* tests weak (dart-lang/co19#2057)
2023-05-22 sgrekhov22@gmail.com Fixes dart-lang/co19#2054. Fix non-initialized variable (dart-lang/co19#2055)
2023-05-17 sgrekhov22@gmail.com dart-lang/co19#1400. Static analysis of an inline member invocation tests (dart-lang/co19#2050)
2023-05-17 sgrekhov22@gmail.com Fixes dart-lang/co19#2051. Typo fixed in syntax_A04_t04.dart (dart-lang/co19#2052)
2023-05-16 sgrekhov22@gmail.com dart-lang/co19#1400. Inline classes syntax tests updated and missing one added (dart-lang/co19#2048)
2023-05-16 sgrekhov22@gmail.com dart-lang/co19#1912. Comments in Const evaluation tests improved (dart-lang/co19#2041)
2023-05-15 devoncarew@google.com blast_repo fixes (dart-lang/co19#2049)
2023-05-15 sgrekhov22@gmail.com Fixes dart-lang/co19#1912. More tests for CONST_CANONICAL_TYPE added (dart-lang/co19#2038)

Change-Id: I10419ad4fc0f325c76a1c0b7033b5a874bc66fd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305220
Reviewed-by: Alexander Thomas <athom@google.com>
@sgrekhov sgrekhov deleted the co19-2059 branch July 18, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants