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

#2976. Add type inference tests. Part 2 #3005

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

sgrekhov
Copy link
Contributor

@sgrekhov sgrekhov commented Dec 5, 2024

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, couple of comments.

One thing needs to be reconsidered: It's the context type schema of .id.a.b.c which is used to compute the static namespace where id is looked up, not the context type schema of .id.

@@ -55,4 +55,9 @@ main() {
// [analyzer] unspecified
// [cfe] unspecified
}.toList();

dynamic v = .parse("42");
Copy link
Member

Choose a reason for hiding this comment

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

OK. I'm not sure dynamic as a context type schema is equivalent to _. But we should have the error anyway, and it's a delicate question, so let's have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Interesting... I can't see that this has been specified anywhere, but the choice of context type schema in every given situation is highly underspecified anyway.

One source of confusion is that the implemented type inference algorithm chooses dynamic in a number of cases where the specification in inference.md says that the inferred result is the greatest closure. I created dart-lang/language#4197 to shed some light on that.

If we assume that this is fixed then I'd expect the following behavior:

X getContextType<X>(Object? o) {
  print(X);
  return o as X;
}

void main() {
  getContextType(1)..arglebargle; // Compile-time error.
  dynamic d = getContextType(1)..arglebargle; // No compile-time error.
}

This should illustrate that the context type schema _ and the context type dynamic is not the same thing. So we still need some clarifications, but I'd maintain that it isn't safe to assume that they are the same thing.

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.

Thank you. I misunderstood the spec at first. Now updated, PTAL

@@ -55,4 +55,9 @@ main() {
// [analyzer] unspecified
// [cfe] unspecified
}.toList();

dynamic v = .parse("42");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sgrekhov sgrekhov requested a review from eernstg December 5, 2024 17:21
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 eernstg merged commit 44b0733 into dart-lang:master Dec 6, 2024
2 checks passed
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Dec 9, 2024
2024-12-06 [email protected] Fixes dart-lang/co19#3008. Rewrite type_inference_A01_t06.dart to get the context type _ (dart-lang/co19#3009)
2024-12-06 [email protected] Fixes dart-lang/co19#3006. Fix a typo in type_inference_A01_t06.dart (dart-lang/co19#3007)
2024-12-06 [email protected] dart-lang/co19#2976. Add type inference tests. Part 2 (dart-lang/co19#3005)
2024-12-05 [email protected] dart-lang/co19#2976. Add more type inference tests (dart-lang/co19#3004)
2024-12-04 [email protected] dart-lang/co19#2976. Add grammar, semantics and type inference test for constants (dart-lang/co19#3003)
2024-11-29 [email protected] dart-lang/co19#2976. Add more grammar, semantics and type inference test (dart-lang/co19#3002)

Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try
Change-Id: Ie10a17900bc7d61d4f9288d3e3d2f359eca4f1d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399400
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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants