compilation unit 'FSharp.Core' did not contain the namespace, module or type 'StringModule'
See original GitHub issueDescription
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:
FSC : error FS0193: The module/namespace 'Microsoft.FSharp.Collections' from compilation unit 'FSharp.Core' did not contain the namespace, module or type 'StringModule' [/Users/ben/proj/oss/constrainedtypes/test/ConstrainedTypes.Test/ConstrainedTypes.Test.fsproj]
The type provider is implemented as follows:
namespace ConstrainedTypes
open System.IO
open System.Reflection
open FSharp.Quotations
open ProviderImplementation
open ProviderImplementation.ProvidedTypes
open FSharp.Quotations
open Microsoft.FSharp.Quotations
[<TypeProvider>]
type ConstrainedStringProvider (config : TypeProviderConfig) as this =
inherit TypeProviderForNamespaces (config, addDefaultProbingLocation=true)
let rootNs = "ConstrainedTypes"
let thisAssembly = Assembly.GetExecutingAssembly()
let boundedStringProvider = ProvidedTypeDefinition(thisAssembly, rootNs, "BoundedString", Some typeof<string>)
do
boundedStringProvider.DefineStaticParameters([ProvidedStaticParameter("Length", typeof<int>)], fun name args ->
let length = args.[0] :?> int
let provided = ProvidedTypeDefinition(thisAssembly, rootNs, name, Some typeof<string>)
ProvidedConstructor(
[ProvidedParameter("value", typeof<string>)],
fun args ->
<@@
printfn "checking bound: %d" length
if (length < String.length %%(args.[0])) then
sprintf "provided value exceeded the bounds: '%s' > %d"
%%(args.[0]) length
|> invalidArg "value"
@@>
)
|> provided.AddMember
provided
)
this.AddNamespace(rootNs, [boundedStringProvider])
[<TypeProviderAssembly>]
do ()
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
- MacOS Catalina
- .NET Core 3.1.100
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Build error: The module/namespace 'Microsoft.FSharp. ...
FSharp.Core' from compilation unit 'FSharp.Core' did not contain the namespace, module or type 'string' #2977.
Read more >F# 3.0 compiler error FS0193 when upgrading project
RuntimeHelpers' from compilation unit 'FSharp.Core' did not contain the namespace, module or type 'LeafExpressionConverter'.
Read more >Modules - F# | Microsoft Learn
Learn how an F# module is a grouping of F# code, such as values, types, ... The qualified namespace does not have to...
Read more >FSharp.Core
Indicates a construct is automatically opened when brought into scope through an assembly reference or then opening of the containing namespace or module....
Read more >FSharpSpec-4.1-latest
the f# 4.1 language specification note: this documentation is the specification ... without the type annotation, the f# compiler would not have known...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ops, sorry, my typo As error message says issue is in method accessability. You need to remove
internal
modifier from module declarationReplace
to
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.
simple quotation that call implementation and pass parameters