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 16 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

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.

var member = myTypeAtom.getMember(memberName);
assertThat("Member " + memberName + " should be readable", member, is(notNullValue()));
assertThat("All fields are numbers", member.isNumber(), is(true));
assertThat("Has at least two fields", memberNames.size(), is(greaterThan(2)));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertThat("Has at least two fields", memberNames.size(), is(greaterThan(2)));
assertThat("Has more than two fields", memberNames.size(), is(greaterThan(2)));

@@ -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?


/**
* Returns methods (both instance and static) defined on this type, including the ones inherited
* from Any. Instance methods are defined on this type, static methods are defined on its {@link
Copy link
Member

Choose a reason for hiding this comment

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

Does this work properly for Any, Number, Integer or Float hierarchy? E.g. are methods from Number (if any) also included?

@TruffleBoundary
public Map<String, Function> getMethods(boolean includeStaticMethods) {
var ctx = EnsoContext.get(null);
var allMethods = new HashMap<>(methodsFromAny(ctx));
Copy link
Member

Choose a reason for hiding this comment

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

There is method allTypes() which returns "All types this type represents including super types." - I guess it should be used here somehow to handle the "numbers hierarchy".


group_builder.specify "methods of Integer" <|
Meta.meta Integer . methods . sort . should_equal ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'fits_in_long', 'floor', 'negate', 'round', 'to_decimal', 'to_float', 'truncate']
expected_methods = ['%', '*', '+', '-', '/', '<', '<=', '>', '>=', '^', 'abs', 'bit_and', 'bit_not', 'bit_or', 'bit_shift', 'bit_shift_l', 'bit_shift_r', 'bit_xor', 'ceil', 'div', 'fits_in_long', 'floor', 'negate', 'round', 'to_decimal', 'to_float', 'truncate']
Copy link
Member

Choose a reason for hiding this comment

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

Can you concatenate the expected_methods from three parts?

  • those coming from Any
  • those coming from Number
  • those coming from Integer

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
Development

Successfully merging this pull request may close these issues.

getMembers polyglot message of Type should include methods from Any
3 participants