Description
The F# compiler gives error "FS0193: error : not a nominal type" in a project when it performs operations with an enum provided by a managed C++ project reference.
Specifically, there is a Managed C++ project called ProjectedFSLib.Managed.API that contains a enum called HResult.
In an F# project that references this Managed C++ project, as soon as any F# expressions operate on that enum, the F# compilation fails with "FS0193: error : not a nominal type".
Repro steps
Provide the steps required to reproduce the problem:
- Clone this repository:
https://github.com/jhorv/ProjFS-Managed-API/tree/fs-compiler-error-FS0193
This repo is a fork of Microsoft's Projected Filesystem managed API project. My changes are simply to reimplement their sample, the "SimpleProviderManaged" C# project, in F# to a) play with F# and b) experiment with the Microsoft Projected FS API.
- Open in Visual Studio 2019
- Restore Nuget packages and compile. The F# compiler will fail with FS0193 errors.
Expected behavior
The code to compile successfully.
Actual behavior
The compilation fails with the following stack trace:
3>optimize error FS0193: error : not a nominal type
3>parameter error FS0193: error : not a nominal type
3> Unhandled Exception: System.InvalidOperationException: not a nominal type
3> at FSharp.Compiler.AbstractIL.IL.ILType.get_TypeSpec()
3> at FSharp.Compiler.Tastops.underlyingTypeOfEnumTy$cont@4773(TcGlobals g, TypeDefMetadata matchValue, Unit unitVar)
3> at FSharp.Compiler.Tastops.underlyingTypeOfEnumTy(TcGlobals g, TType ty)
3> at FSharp.Compiler.Tastops.checkTypes@4814(TcGlobals g, TType a, TType b)
3> at FSharp.Compiler.Tastops.decideStaticOptimizationConstraint(TcGlobals g, StaticOptimization c)
3> at FSharp.Compiler.Tastops.DecideStaticOptimizations(TcGlobals g, FSharpList1 cs) 3> at FSharp.Compiler.Tastops.mkStaticOptimizationExpr(TcGlobals g, FSharpList
1 cs, Expr e1, Expr e2, range m)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.remapExpr(TcGlobals g, ValCopyFlag compgen, Remap tmenv, Expr expr)
3> at FSharp.Compiler.Tastops.MakeApplicationAndBetaReduceAux(TcGlobals g, Expr f, TType fty, FSharpList1 tyargsl, FSharpList
1 argsl, range m)
3> at FSharp.Compiler.Optimizer.OptimizeApplication(cenv cenv, IncrementalOptimizationEnv env, Expr f0, TType f0ty, FSharpList1 tyargs, FSharpList
1 args, range m)
3> at FSharp.Compiler.Optimizer.OptimizeSwitch(cenv cenv, IncrementalOptimizationEnv env, Expr e, FSharpList1 cases, FSharpOption
1 dflt, range m)
3> at FSharp.Compiler.Optimizer.OptimizeLinearExpr(cenv cenv, IncrementalOptimizationEnv env, Expr expr, FSharpFunc2 contf) 3> at FSharp.Compiler.Optimizer.OptimizeLinearExpr(cenv cenv, IncrementalOptimizationEnv env, Expr expr, FSharpFunc
2 contf)
3> at FSharp.Compiler.Optimizer.OptimizeLambdas(FSharpOption1 vspec, cenv cenv, IncrementalOptimizationEnv env, ValReprInfo topValInfo, Expr e, TType ety) 3> at FSharp.Compiler.Optimizer.OptimizeBinding(cenv cenv, Boolean isRec, IncrementalOptimizationEnv env, Binding _arg4) 3> at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn) 3> at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m) 3> at FSharp.Compiler.Optimizer.OptimizeBinding(cenv cenv, Boolean isRec, IncrementalOptimizationEnv env, Binding _arg4) 3> at FSharp.Compiler.Optimizer.OptimizeModuleBinding(cenv cenv, IncrementalOptimizationEnv env, FSharpList
1 bindInfosColl, ModuleOrNamespaceBinding x)
3> at [email protected](ModuleOrNamespaceBinding x)
3> at Microsoft.FSharp.Primitives.Basics.List.mapFoldToFreshConsTail[TResult,TState,T](FSharpList1 cons, FSharpFunc
3 f, TState acc, FSharpList1 xs) 3> at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc
2 f, TState acc, FSharpList1 xs) 3> at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult](FSharpFunc
2 mapping, TState state, FSharpList1 list) 3> at FSharp.Compiler.Optimizer.OptimizeModuleDef(cenv cenv, IncrementalOptimizationEnv env, FSharpList
1 bindInfosColl, ModuleOrNamespaceExpr x)
3> at [email protected](ModuleOrNamespaceExpr x)
3> at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc2 f, TState acc, FSharpList
1 xs)
3> at FSharp.Compiler.Optimizer.OptimizeModuleDefs(cenv cenv, IncrementalOptimizationEnv env, FSharpList1 bindInfosColl, FSharpList
1 defs)
3> at FSharp.Compiler.Optimizer.OptimizeModuleDef(cenv cenv, IncrementalOptimizationEnv env, FSharpList1 bindInfosColl, ModuleOrNamespaceExpr x) 3> at FSharp.Compiler.Optimizer.OptimizeModuleBinding(cenv cenv, IncrementalOptimizationEnv env, FSharpList
1 bindInfosColl, ModuleOrNamespaceBinding x)
3> at [email protected](ModuleOrNamespaceBinding x)
3> at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc2 f, TState acc, FSharpList
1 xs)
3> at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult](FSharpFunc2 mapping, TState state, FSharpList
1 list)
3> at FSharp.Compiler.Optimizer.OptimizeModuleDef(cenv cenv, IncrementalOptimizationEnv env, FSharpList1 bindInfosColl, ModuleOrNamespaceExpr x) 3> at [email protected](ModuleOrNamespaceExpr x) 3> at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc
2 f, TState acc, FSharpList1 xs) 3> at FSharp.Compiler.Optimizer.OptimizeModuleDefs(cenv cenv, IncrementalOptimizationEnv env, FSharpList
1 bindInfosColl, FSharpList1 defs) 3> at FSharp.Compiler.Optimizer.OptimizeModuleDef(cenv cenv, IncrementalOptimizationEnv env, FSharpList
1 bindInfosColl, ModuleOrNamespaceExpr x)
3> at FSharp.Compiler.Optimizer.OptimizeModuleExpr(cenv cenv, IncrementalOptimizationEnv env, ModuleOrNamespaceExprWithSig x)
3> at FSharp.Compiler.Optimizer.OptimizeImplFileInternal(cenv cenv, IncrementalOptimizationEnv env, Boolean isIncrementalFragment, SignatureHidingInfo hidden, TypedImplFile _arg5)
3> at FSharp.Compiler.Optimizer.OptimizeImplFile(OptimizationSettings settings, CcuThunk ccu, TcGlobals tcGlobals, FSharpFunc2 tcVal, ImportMap importMap, IncrementalOptimizationEnv optEnv, Boolean isIncrementalFragment, Boolean emitTaicalls, SignatureHidingInfo hidden, TypedImplFile mimpls) 3> at FSharp.Compiler.CompileOptions.ApplyAllOptimizations@1703-1.Invoke(TypedImplFile implFile) 3> at Microsoft.FSharp.Primitives.Basics.List.mapFoldToFreshConsTail[TResult,TState,T](FSharpList
1 cons, FSharpFunc3 f, TState acc, FSharpList
1 xs)
3> at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc2 f, TState acc, FSharpList
1 xs)
3> at FSharp.Compiler.CompileOptions.ApplyAllOptimizations(TcConfig tcConfig, TcGlobals tcGlobals, FSharpFunc2 tcVal, String outfile, ImportMap importMap, Boolean isIncrementalFragment, IncrementalOptimizationEnv optEnv, CcuThunk ccu, FSharpList
1 implFiles)
3> at FSharp.Compiler.Driver.main2a[a,b,c,d,e,f,g](Args1 _arg1) 3> at FSharp.Compiler.Driver.typecheckAndCompile(CompilationThreadToken ctok, String[] argv, Resolver legacyReferenceResolver, Boolean bannerAlreadyPrinted, ReduceMemoryFlag reduceMemoryUsage, CopyFSharpCoreFlag defaultCopyFSharpCore, Exiter exiter, ErrorLoggerProvider loggerProvider, FSharpOption
1 tcImportsCapture, FSharpOption`1 dynamicAssemblyCreator)
3> at FSharp.Compiler.CommandLineMain.Driver.main(String[] argv)
3> at FSharp.Compiler.CommandLineMain.main(String[] argv)
3> at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
3> at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
3> at FSharp.Compiler.CommandLineMain.main(String[] argv)
3> The command exited with code -532462766.
Known workarounds
None
Related information
Provide any related information (optional):
I encountered this same problem on 2 different computers, though both were running:
- latest Windows 10 non-insider version: Version 1903, OS build 18362.295
- the F# project is .NET Framework 4.6.1, same as the C# project I'm re-implementing
- Visual Studio 2019 16.2.3
Metadata
Metadata
Assignees
Labels
Type
Projects
Status