fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

"Type mismatch when building 'expr'" error on quotations #333

Closed Jand42 closed 4 years ago

Jand42 commented 4 years ago

Description

The F# compiler can give a Type mismatch when building 'expr' error on two types which should be the same during the running of a TP. Found when building https://github.com/dotnet-websharper/ui and this is a breaking change introduced by #332, works with the previous state (e9d2c93).

Example of error:

 The type provider 'WebSharper.UI.Templating.TemplatingProvider' reported an error in the context of provided type 'WebSharper.UI.Templating.Template,pathOrHtml="index.html,template.html",clientLoad="2",legacyMode="3"+template', member 'NewDescription'. The error: Type mismatch when building 'expr': the expression has the wrong type. Expected 'WebSharper.UI.Var`1[System.String]', but received type 'WebSharper.UI.Var`1[System.String]'.Parameter name: receivedType

The WebSharper.UI.Templating type provider uses expression splicing extensively, probably the issue is related to that, I am experimenting to find a minimal failing test case and will update this description if found.

Repro steps

Expected behavior

WebSharper.UI.Templating.Tests project should build as before, now fails on erased TP use.

Actual behavior

Build errors.

Known workarounds

Use earlier state of FSharp.TypeProviders.SDK.

Related information

sergey-tihon commented 4 years ago

cc @thinkbeforecoding

thinkbeforecoding commented 4 years ago

332 was actually done to build methods that have parameters or return types that are RuntimeType generics (like Task<'t> or Async<'t>) of generated type.

Previously, the handling of method parameters used t.MakeGeneric which returns such generic that doesn't work then for generation.. I may have broken your usecase in the process. A repro would ease the fix

thinkbeforecoding commented 4 years ago

I tested your sample with this fix from #335 and it now seems to work correctly 👍