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

Custom operator not used or resolved for erased type... sometimes. #2915

Open
IanManske opened this issue Jun 1, 2022 · 3 comments
Open

Comments

@IanManske
Copy link
Contributor

Description

For an erased type, a custom member operator sometimes doesn't get used or resolved. The code below shows a function that correctly applies the operator and another that incorrectly ends up using the default + operator in the outputted JS. Changing the custom operator from + to == gives fable compile errors for both functions: Cannot resolve trait call. Removing the Erase attribute causes the code to compile correctly in both cases.

Repo code

REPL Code.

Expected and actual results

Expected:

export function add2(x, y) {
    return WrappedNum_op_Addition_Z51B1C440(x, new WrappedNum(0, y));
}

Actual:

export function add2(x, y) {
    return x + y;
}

Related information

  • Fable version: 3.7.10 on REPL, also tested on 3.7.12
  • Operating system: N/A
@alfonsogarciacaro
Copy link
Member

Sorry @IanManske! For some reason when reviewing the issues I confused this with #2880 and thought it was already fixed.

This is a bit tricky because currently Fable discards type info for erased types so operator resolution (which needs the type info as it works similar to SRTP) doesn't work. We're currently considering to include the type info for erased types which hopefully should make this work. See #2914

@IanManske
Copy link
Contributor Author

No worries! Thanks for the response.
For #2914, it might make sense for "when using a union just to wrap a primitive, then it should probably become the type of the primitive."
But would this result in dropping/losing members and operators defined for the union?
Then again, I'm also not sure how common it is for Fable users to add members on erased unions that wrap primitives.

@alfonsogarciacaro
Copy link
Member

Ah, yeah. You're right! I guess we'll have to keep the full type info and "erase" only when emitting the final JS code.

alfonsogarciacaro added a commit that referenced this issue Nov 20, 2022
alfonsogarciacaro added a commit that referenced this issue Nov 23, 2022
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

No branches or pull requests

2 participants