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

Members on Atom and Type include inherited methods from Any #12099

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented Jan 21, 2025

Fixes #12045 and #6303

Pull Request Description

getMembers interop message on Atom and on Type now include inherited methods from super types.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@Akirathan Akirathan added CI: No changelog needed Do not require a changelog entry for this PR. CI: Clean build required CI runners will be cleaned before and after this PR is built. labels Jan 21, 2025
@Akirathan Akirathan self-assigned this Jan 21, 2025
@Akirathan Akirathan changed the title Test members on Atom and Type include inherited methods from Any Members on Atom and Type include inherited methods from Any Jan 22, 2025
@Akirathan Akirathan marked this pull request as ready for review January 22, 2025 13:32
vector_methods = Hashset.from_vector <| Meta.meta Vector . methods
array_methods = Hashset.from_vector <| Meta.meta Array . methods
diff = array_methods.difference vector_methods
Test.with_clue "The difference should be empty, but was: "+diff.to_text <|
Copy link
Contributor

Choose a reason for hiding this comment

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

Would a simple .should_equal work here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because Vector's methods are a superset of Array's methods, which is expected. For example, there is Vector.from_array and Vector.from_polyglot_array which is not on Array, and that is fine.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

I am surprised the code in Type isn't using allTypes(...), but hardcodes anyMethods. I'd expect more generic code.

@@ -2428,7 +2428,7 @@ class RuntimeErrorsTest
contextId,
mainResId,
Api.ExpressionUpdate.Payload.Panic(
"Compile_Error",
"Compile_Error.Error",
Copy link
Member

Choose a reason for hiding this comment

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

Why has this changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was about to ask @4e6 to give me a clue why this change is needed. I have no idea which part is responsible for providing this panic payload.

test/Base_Tests/src/Semantic/Meta_Spec.enso Outdated Show resolved Hide resolved
var allMethods = new HashMap<String, Function>();
for (var type : allTypes(ctx)) {
var methodsOnThisType = type.methodsOnThisType(includeStaticMethods);
allMethods.putAll(methodsOnThisType);
Copy link
Member

Choose a reason for hiding this comment

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

What if there are overrides? This code will likely put the Any.to_text into the map and not My_Type.to_text... it may not matter as type.getMethods(true).keySet() - e.g. only keys are used, but then this method should be changed to Set<String> and not provide incorrect .values().

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 80e80e4 - methods with same name from subtypes are kept in the map and not replaced by the methods from supertypes. In other words, overridden methods are preferred.

@enso-bot enso-bot bot mentioned this pull request Jan 24, 2025
@Akirathan
Copy link
Member Author

Added test for consistency between method invocation on types in pure Enso, and method invocation on types via interop protocol in b95e3ea. I believe that at this moment, this test sufficiently covers the functionality of method dispatch in Type.invokeMember. We should add a similar test for Atoms in separate PR as well. Moreover, this test can, obviously, be extended to provide all the values from ValuesGenerator to increase the coverage even more.

remove_us = locale_meta.methods + ["Value", "new", "default", "from_language_tag", "from_java", "predefined_locale_fields", "default_widget", "widget_options"]
Meta.Type.Value (Meta.type_of locale_meta.value) . methods . filter (Filter_Condition.Is_In remove_us ..Remove) . sort
methods_to_remove = Vector.build bldr->
bldr.append "Value"
Copy link
Member

Choose a reason for hiding this comment

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

This one should be private unless something horribly breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
3 participants