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

[extension types] Adjust the paragraph about Object members: They do not need special treatment #3395

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Oct 12, 2023

The extension type feature specification used to have a paragraph about invocations of members of Object (hashCode, operator ==, etc). It stated that the signature was taken from Object?. This is not consistent with a situation like the following, because all other non-extension type members would be treated according to the signature known from the traversal of the superinterface graph.

This PR changes the given paragraph to commentary, and changes the text to simply say that members of Object receive exactly the same treatment as all other non-extension type members. This yields the following behavior:

class A {
  void foo() {}
}

class B implements A {
  @override
  void foo([int i = 0]) {}

  @override
  String toString([bool whatever = true]) => super.toString();
}


extension type E1(B b) implements A {}

extension type E2(B b) implements E1, B {}

void main() {
  var e2 = E2(B());
  var e1 = e2; // OK, `E2 <: E1`.
  
  e2.foo(42); // OK, signature is `void foo([int])`.
  e2.toString(true); // OK, signature is `String toString([bool])`.
  
  e1.foo(42); // Compile-time error, signature `void foo()`.
  e1.toString(true); // Compile-time error, signature `String toString()`.
}

Note that we need to take the combined member signature of foo in E2: E1 contributes the signature void foo() and B contributes the signature void foo([int]), and the combined member signature is then void foo([int]). The signature for toString in E2 is computed in the same manner (as mentioned in the title: there is no need to special-case members of Object).

@eernstg eernstg requested a review from lrhn October 12, 2023 09:22
Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

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

Ship it!
(We need tests. Lots of test.)

@eernstg eernstg changed the title Adjust the paragraph about Object members: They do not need special treatment [extension types] Adjust the paragraph about Object members: They do not need special treatment Oct 12, 2023
@eernstg
Copy link
Member Author

eernstg commented Oct 12, 2023

@sgrekhov, could you take a look at the co19 tests in this area, possibly adjusting existing ones and adding new ones?

@eernstg eernstg merged commit 004e8cd into main Oct 12, 2023
3 checks passed
@eernstg eernstg deleted the spec_Object_signature_oct23 branch October 12, 2023 09:32
@sgrekhov
Copy link
Contributor

dart-lang/co19#2304

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants