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

Generate an error at compilation if trying to call an erased constructor #3851

Open
MangelMaxime opened this issue Jun 15, 2024 Discussed in #3850 · 0 comments
Open

Generate an error at compilation if trying to call an erased constructor #3851

MangelMaxime opened this issue Jun 15, 2024 Discussed in #3850 · 0 comments

Comments

@MangelMaxime
Copy link
Member

Discussed in #3850

Originally posted by joprice June 15, 2024
When a type has the Erase attribute, you can still attempt to call the constructor. The code will generate a call to the name-mangled ctor wrapper, which doesn't exist, and fail at runtime. I would expect this to fail at compile time with an error such as "no constructor exists for erased type X". Of course, this might be easier said than done, and not sure if there's some reason it works this way.

This also might seem like a bit of a contrived case, but I've hit this multiple times in the few weeks I've been using fable, where I modify existing code, starting with some static functions and Erased to avoid the reflection and constructor generation, then switching to have some state and forgetting to remove it.

open Fable.Core

[<Erase>]
type X(a: string) = 
 member _.getA() = a

let create() = X("a")

https://fable.io/repl/#?code=PYBwpgdgBAYghgIwDZgHQGFgCcwFgBQBA2gDwCiWcAzmAHwC6BALgJ7hQAaAFHAFxRUmWAJYQA5gEooAXigEoUALZhFCMFigB9VGLBMAglymy4BAiiZQAxjjhMwRmZy4AiOC4lA&html=Q&css=Q

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

No branches or pull requests

1 participant