dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
589 stars 52 forks source link

Macros applied on types run first #1383

Closed Jooseppi12 closed 5 months ago

Jooseppi12 commented 5 months ago

Given a scenario like this:

[<Macro(typeof<...>, true)>]
type X =
    abstract Y: int -> int
    abstract Z: string -> string

We need a way to ensure our Macro is able to be applied to all members on the interface. The idea is to add an extra flag for the Macro type to enable this behavior, as Macros are used as fallback implementations in certain scenarios.

Jand42 commented 5 months ago

@Jooseppi12 The only macros that WS.Core uses on types for which the proxies are also using explicit members are for numerics and tuples. I don't think many other people/libraries would use macros on classes. I think it's better to have a breaking change for a somewhat obscure use case than introducing more complexity.

So I would rather: have macros defined for types execute always, for any calls to members on that type. Within the macro itself, if you don't want to handle the call, it can return MacroFallback (this is how multiple macros can be chained, or fall back to inline or JS implementation etc.)