Replies: 8 comments
-
Can you please try to create TP from the template?
Update samples provider with our code, but does not remove
|
Beta Was this translation helpful? Give feedback.
-
@sergey-tihon I'm not sure I understand what this means. Are you asking me to take the provider code from the template and update it with my implementation, but be sure to leave the |
Beta Was this translation helpful? Give feedback.
-
@sergey-tihon I've reimplemented my TP from the template as you suggested here: https://github.com/aggieben/constrainedtypes/tree/tpsdk-343 It fails in the same way.
|
Beta Was this translation helpful? Give feedback.
-
Thank you, it definitely looks like a bug of mapping types from quotation to target runtime types. It is a good practice to keep quotations as small as possible. You can move method implementation into runtime assembly and just call it from quotation. [<AutoOpen>]
module internal Utilities =
let x = 1
let ctorBoundedString length str =
if (length < String.length str) then
sprintf "provided value exceeds the bounds: '%s' > %d"
str length
|> invalidArg "value" simple quotation that call implementation and pass parameters ProvidedConstructor(
[ProvidedParameter("value", typeof<string>)],
fun args -> <@@ ctorBoundedString length %%(args.[0]) @@>
)
|> boundedStringType.AddMember |
Beta Was this translation helpful? Give feedback.
-
@sergey-tihon alright, thanks. I'll give that a go. Is it necessary to have separate runtime and design-time components? |
Beta Was this translation helpful? Give feedback.
-
It it not mandatory, so it should be possible to keep both components in one assembly.
|
Beta Was this translation helpful? Give feedback.
-
@sergey-tihon I moved the bounds-checking function to the utility module in the runtime component as you suggested, but the tests now fail with this error:
This same error is emitted from both the combined provider (on my |
Beta Was this translation helpful? Give feedback.
-
ops, sorry, my typo Replace module internal Utilities = to module Utilities = |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I wrote a simple type provider that references
String.length
in the untyped quotation used to provide a constructor implementation. The type provider library builds, but a consuming project fails to build with the following error:The type provider is implemented as follows:
This implementation can be cloned here: https://github.com/aggieben/constrainedtypes
Repro steps
See implementation above. Clone the linked implementation and build the
ConstrainedTypes.Test
project to repro.Expected behavior
I expected the use of the provided type
BoundedString<10>
to compile.Actual behavior
The type provider fails at consumer compile time.
Known workarounds
None
Related information
Beta Was this translation helpful? Give feedback.
All reactions