Skip to content

#2342. Update nullability tests according to the new rules #2385

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

Merged
merged 3 commits into from
Nov 21, 2023

Conversation

sgrekhov
Copy link
Contributor

No description provided.

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.

Looks good! There are a couple of typos.

A more pervasive issue is that an @assertion includes a sentence from the feature specification which is misleading (it will be fixed, but hasn't been fixed at this time).

I'm not sure what's the best way to proceed with that, maybe just leave it as is and create an issue about updating it when the spec is updated?

/// @description Checks that if an instantiated representation type `R` is
/// not non-nullable then it is a proper subtype of `Object?` (can be assigned
/// to `Object?`)
/// @description Checks that if an extension type doesn't implement subtype of
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps:

Suggested change
/// @description Checks that if an extension type doesn't implement subtype of
/// @description Checks that even if an extension type doesn't implement a subtype of

The word 'even' is there to indicate that the following isn't implied: "If an extension type E does implement a subtype of Object then E isn't a subtype of Object?".

Copy link
Member

Choose a reason for hiding this comment

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

There are a couple of other occurrences of 'implement subtype'.

Copy link
Contributor Author

@sgrekhov sgrekhov left a comment

Choose a reason for hiding this comment

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

Updated. Please take another look

@sgrekhov sgrekhov requested a review from eernstg November 20, 2023 14:46
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.

Just one confusing test:LanguageFeatures/Extension-types/static_analysis_extension_types_A17_t04.dart.

/// compile-time error to assign `Object?` or `null` to `V`)
/// @description Checks that if an extension type doesn't implement a subtype of
/// `Object` then is potentially non-nullable (it's a compile-time error to
/// assign `Object?` or `null` to it)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I overlooked something that Object? can do here? Otherwise I'd think it can be omitted:

'Being potentially non-nullable' is the same thing as the negation of 'being nullable'. This means that it is a compile-time error to assign null to it. However, assigning something of type Object? to it is a compile-time error for a lot of other reasons, so that's probably not worth testing here (it's going to test a bunch of other properties, but they are probably being tested in various other tests already).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is to test that an extension type is a proper subtype of Object?, i.e. it can be assigned to Object? but Object? cannot be assigned to it. And this test checks the latter. Do you believe that we should check here assigning of the null only?

Copy link
Member

Choose a reason for hiding this comment

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

OK, but then we just need to make sure that the description says 'proper' at some point, because that's the part that justifies checking that we can't assign an expression of type Object? to a variable whose type is an extension type that doesn't implement Object.

Copy link
Member

Choose a reason for hiding this comment

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

Looking again, it seems likely that the test where 'proper subtype' should actually be tested is LanguageFeatures/Extension-types/static_analysis_extension_types_A17_t03.dart.

So if the tests about assigning Object? to an extension typed variable are added over there and deleted from here then I think we'll have a good alignment between the contents of the tests and the descriptions of the tests.

Of course there could be other ways to reorganize that would create a similarly precise alignment, but I do think it would be great if something is done about the fact that t03 says "proper subtype" but doesn't test more than half of it, and this test doesn't say "proper subtype", but it does test the halfpart that was missing from t03. ;-)


main() {
V1 v1_1 = V1(42) as Object?;
// ^^^^^^^^^^^^^^^^^
// ^
Copy link
Member

Choose a reason for hiding this comment

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

Surely I did miss something - why would the cast be flagged (unnecessary_cast?), but the initializing expression as a whole is not (even though it has static type Object? and is used to initialize a variable of type V1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just according the current behaviour of the tools. They report an error there

static_analysis_extension_types_A17_t04.dart:24:20: Error: A value of type 'Object?' can't be assigned to a variable of type 'V1'.
 - 'Object' is from 'dart:core'.
  V1 v1_1 = V1(42) as Object?;
                   ^

@sgrekhov sgrekhov requested a review from eernstg November 21, 2023 12:54
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.

Looks good!

Just one thing: I think it would be great if the discrepancy between the description and the actual test for LanguageFeatures/Extension-types/static_analysis_extension_types_A17_t0{3.4}.dart is resolved.

/// compile-time error to assign `Object?` or `null` to `V`)
/// @description Checks that if an extension type doesn't implement a subtype of
/// `Object` then is potentially non-nullable (it's a compile-time error to
/// assign `Object?` or `null` to it)
Copy link
Member

Choose a reason for hiding this comment

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

OK, but then we just need to make sure that the description says 'proper' at some point, because that's the part that justifies checking that we can't assign an expression of type Object? to a variable whose type is an extension type that doesn't implement Object.

/// compile-time error to assign `Object?` or `null` to `V`)
/// @description Checks that if an extension type doesn't implement a subtype of
/// `Object` then is potentially non-nullable (it's a compile-time error to
/// assign `Object?` or `null` to it)
Copy link
Member

Choose a reason for hiding this comment

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

Looking again, it seems likely that the test where 'proper subtype' should actually be tested is LanguageFeatures/Extension-types/static_analysis_extension_types_A17_t03.dart.

So if the tests about assigning Object? to an extension typed variable are added over there and deleted from here then I think we'll have a good alignment between the contents of the tests and the descriptions of the tests.

Of course there could be other ways to reorganize that would create a similarly precise alignment, but I do think it would be great if something is done about the fact that t03 says "proper subtype" but doesn't test more than half of it, and this test doesn't say "proper subtype", but it does test the halfpart that was missing from t03. ;-)

@sgrekhov
Copy link
Contributor Author

Moved V1 v1_1 = V1(42) as Object?; tests from static_analysis_extension_types_A17_t03.dart to static_analysis_extension_types_A17_t04.dart

@sgrekhov sgrekhov requested a review from eernstg November 21, 2023 14:32
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

@eernstg
Copy link
Member

eernstg commented Nov 21, 2023

Great, thanks!

@eernstg eernstg merged commit 55f9ad0 into dart-lang:master Nov 21, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Nov 24, 2023
2023-11-23 [email protected] Merge pull request dart-lang/co19#2395 from dart-lang/merge-pre-nnbd
2023-11-23 [email protected] Fixes dart-lang/co19#2390. Fix tests according to the new method/setter rules (dart-lang/co19#2392)
2023-11-23 [email protected] Fixes dart-lang/co19#2388. Add tests for the new method/setter rules. Update assertions (dart-lang/co19#2393)
2023-11-23 [email protected] Merge remote-tracking branch 'origin/pre-nnbd' into master
2023-11-22 [email protected] Fixes dart-lang/co19#2389. Add additional error expectation for analyzer (dart-lang/co19#2391)
2023-11-21 [email protected] dart-lang/co19#2342. Update nullability tests according to the new rules (dart-lang/co19#2385)
2023-11-21 [email protected] Fixes dart-lang/co19#2384. Fix not well-bound extension types. Add function-type dynamic test (dart-lang/co19#2387)

Change-Id: Ic3848f6f39fd42b01bfed5feac3d922c6f5a53d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338120
Reviewed-by: Erik Ernst <[email protected]>
Reviewed-by: Alexander Thomas <[email protected]>
@sgrekhov sgrekhov deleted the co19-2342 branch January 21, 2025 09:33
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