Skip to content

Conversation

@Shmew
Copy link
Contributor

@Shmew Shmew commented Oct 23, 2020

This adds the test case to show how overload resolution doesn't function quite the same when doing some hacky stuff to make units of measure overloads work.

Here you can see Expecto runs the overload cases correctly (BTW there are a couple tests failing):

image

However when running via Mocha:

image

@alfonsogarciacaro
Copy link
Member

This seems to be not an issue with Fable overload suffixes as I thought at first, units of measure are correctly being represented in the hash. However because you're using the inline trick to resolve the overload, Fable gets confused. F# witnesses should help with this. They seem to have been fixed in FCS so we can try this out after merging the feature.

You're probably aware of this but if we use "normal" methods, F# compilation fails because the signatures are not different after erasing units of measure.

type ToLength = ToLength with
    static member Make(x: int<px>) = String.Join("", string x, "px")
    static member Make(x: int<em>) = String.Join("", string x, "em")

// Duplicate method. The method 'Make' has the same name and signature as another method in type 'ToLength' once tuples, functions, units of measure and/or provided types are erased. (code 438)

A trick to work around this without inlining is to add a "phantom" optional type, which works with Fable. You can try this or we can wait for F# witnesses and see.

type ToLength = ToLength with
    static member Make(x: int<px>, ?_phantom: int) = String.Join("", string x, "px")
    static member Make(x: int<em>, ?_phantom: int * int) = String.Join("", string x, "em")

@Shmew
Copy link
Contributor Author

Shmew commented Oct 27, 2020

Oh that's an interesting idea. I'll try it out when I get a chance.

@alfonsogarciacaro alfonsogarciacaro changed the base branch from nagareyama to witnesses2 October 31, 2020 01:37
@alfonsogarciacaro alfonsogarciacaro merged commit 66a007d into fable-compiler:witnesses2 Oct 31, 2020
@Shmew Shmew deleted the operator-overloads branch November 1, 2020 01:46
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