fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Compiler fails with internal error when user forgets the Measure attribute when extending a generic type which requires it

Open BillHally opened this issue 5 years ago • 1 comments

If you create a generic type which takes a measure type parameter, but forget to add the Measure attribute when extending the type, the compiler crashes with an internal error.

Repro steps

  1. Paste the following text into a file:
type A<[<Measure>]'u>(x : int<'u>) =
    member __.X = x

module M =
    type A<'u> with // Note the missing Measure attribute
        member this.Y = this.X

[<EntryPoint>]
let main argv = 0
  1. Try to compile the code:
fsc Program.fs

Expected behavior

The compiler provides the user with a helpful error message explaining the problem.

Actual behavior

The compiler reports an internal error 10 times, then crashes:

Microsoft (R) F# Compiler version 10.5.0.0 for F# 4.6
Copyright (c) Microsoft Corporation. All Rights Reserved.

Ok.fs(6,25): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(6,25): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(5,5): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(5,5): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(4,1): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(1,1): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

Ok.fs(1,1): error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

error FS0192: internal error: remapMeasureAux: incorrect kinds

error FS0073: internal error: remapMeasureAux: incorrect kinds (Failure)

error FS0192: internal error: remapMeasureAux: incorrect kinds

Unhandled Exception: System.Exception: remapMeasureAux: incorrect kinds
   at FSharp.Compiler.Tastops.remapMeasureAux(Remap tyenv, Measure unt)
   at FSharp.Compiler.Tastops.remapMeasureAux(Remap tyenv, Measure unt)
   at FSharp.Compiler.Tastops.remapTypeAux(Remap tyenv, TType ty)
   at [email protected](TType ty)
   at FSharp.Compiler.AbstractIL.Internal.Library.List.mapq[T](FSharpFunc`2 f, FSharpList`1 inp)
   at FSharp.Compiler.Tastops.remapTypeAux(Remap tyenv, TType ty)
   at FSharp.Compiler.Tastops.instType(FSharpList`1 tpinst, TType x)
   at [email protected](TType arg10@)
   at Microsoft.FSharp.Core.OptionModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpOption`1 option)
   at FSharp.Compiler.MethodCalls.CalledMeth`1..ctor(InfoReader infoReader, FSharpOption`1 nameEnv, Boolean isCheckingAttributeCall, FSharpFunc`2 freshenMethInfo, range m, AccessorDomain ad, MethInfo minfo, FSharpList`1 calledTyArgs, FSharpList`1 callerTyArgs, FSharpOption`1 pinfoOpt, FSharpList`1 callerObjArgTys, FSharpList`1 curriedCallerArgs, Boolean allowParamArgs, Boolean allowOutAndOptArgs, FSharpOption`1 tyargsOpt)
   at FSharp.Compiler.TypeChecker.makeOneCalledMeth@9826(Boolean isCheckingAttributeCall, cenv cenv, TcEnv env, FSharpOption`1 tyargsOpt, range mMethExpr, range mItem, FSharpOption`1 objTyOpt, AccessorDomain ad, FSharpList`1 callerObjArgTys, FSharpList`1 callerArgs, MethInfo tupledArg0, FSharpOption`1 tupledArg1, Boolean tupledArg2)
   at FSharp.Compiler.TypeChecker.preArgumentTypeCheckingCalledMethGroup@9835.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at FSharp.Compiler.TypeChecker.TcMethodApplication(Boolean isCheckingAttributeCall, cenv cenv, TcEnv env, SyntacticUnscopedTyparEnv tpenv, FSharpOption`1 tyargsOpt, FSharpList`1 objArgs, range mMethExpr, range mItem, String methodName, FSharpOption`1 objTyOpt, AccessorDomain ad, Mutates mut, Boolean isProp, FSharpList`1 calledMethsAndProps, AfterResolution afterResolution, ValUseFlag isSuperInit, FSharpList`1 curriedCallerArgs, TType exprTy, FSharpList`1 delayed)
   at FSharp.Compiler.TypeChecker.TcMethodApplicationThen(cenv cenv, TcEnv env, TType overallTy, FSharpOption`1 objTyOpt, SyntacticUnscopedTyparEnv tpenv, FSharpOption`1 callerTyArgs, FSharpList`1 objArgs, range m, range mItem, String methodName, AccessorDomain ad, Mutates mut, Boolean isProp, FSharpList`1 meths, AfterResolution afterResolution, ValUseFlag isSuperInit, FSharpList`1 args, ExprAtomicFlag atomicFlag, FSharpList`1 delayed)
   at FSharp.Compiler.TypeChecker.TcExpr(cenv cenv, TType ty, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr expr)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcExpr(cenv cenv, TType ty, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr expr)
   at FSharp.Compiler.TypeChecker.TcIteratedLambdas(cenv cenv, Boolean isFirst, TcEnv env, TType overallTy, FSharpSet`1 takenNames, SyntacticUnscopedTyparEnv tpenv, SynExpr e)
   at FSharp.Compiler.TypeChecker.TcIteratedLambdas(cenv cenv, Boolean isFirst, TcEnv env, TType overallTy, FSharpSet`1 takenNames, SyntacticUnscopedTyparEnv tpenv, SynExpr e)
   at FSharp.Compiler.TypeChecker.TcIteratedLambdas(cenv cenv, Boolean isFirst, TcEnv env, TType overallTy, FSharpSet`1 takenNames, SyntacticUnscopedTyparEnv tpenv, SynExpr e)
   at FSharp.Compiler.TypeChecker.TcExprUndelayed(cenv cenv, TType overallTy, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr synExpr)
   at FSharp.Compiler.TypeChecker.TcExpr(cenv cenv, TType ty, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr expr)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcExpr(cenv cenv, TType ty, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr expr)
   at FSharp.Compiler.TypeChecker.TcExprThatCantBeCtorBody(cenv cenv, TType overallTy, TcEnv env, SyntacticUnscopedTyparEnv tpenv, SynExpr expr)
   at FSharp.Compiler.TypeChecker.f@514-18(cenv cenv, FSharpOption`1 safeThisValOpt, SafeInitData safeInitInfo, SynExpr rhsExpr, TType overallExprTy, SyntacticUnscopedTyparEnv tpenv, TcEnv envinner, Boolean isCtor, Unit unitVar0)
   at FSharp.Compiler.TypeChecker.TcNormalizedBinding(DeclKind declKind, cenv cenv, TcEnv env, SyntacticUnscopedTyparEnv tpenv, TType overallTy, FSharpOption`1 safeThisValOpt, SafeInitData safeInitInfo, FSharpList`1 enclosingDeclaredTypars, ExplicitTyparInfo _arg9, NormalizedBinding bind)
   at FSharp.Compiler.TypeChecker.TcLetrecBinding(cenv cenv, TcEnv envRec, range scopem, FSharpList`1 extraGeneralizableTypars, FSharpOption`1 reqdThisValTyOpt, TcEnv envNonRec, FSharpList`1 generalizedRecBinds, FSharpList`1 preGeneralizationRecBinds, SyntacticUnscopedTyparEnv tpenv, FSharpMap`2 uncheckedRecBindsTable, PreCheckingRecursiveBinding rbind)           at FSharp.Compiler.TypeChecker.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization@13752-2.Invoke(Tuple`7 innerState, TyconBindingPhase2A defnA)
   at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, FSharpList`1 xs)
   at FSharp.Compiler.TypeChecker.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization@13704.Invoke(Tuple`5 outerState, TcEnv envForDecls, MutRecShape`5 defnsA)
   at FSharp.Compiler.TypeChecker.MutRecShapes.mapFoldWithEnv@3667.Invoke(a z, MutRecShape`5 x)
   at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, FSharpList`1 xs)
   at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult](FSharpFunc`2 mapping, TState state, FSharpList`1 list)
   at FSharp.Compiler.TypeChecker.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization(cenv cenv, SyntacticUnscopedTyparEnv tpenv, TcEnv envInitial, TcEnv envMutRec, FSharpList`1 defnsAs, FSharpList`1 uncheckedRecBinds, range scopem)
   at FSharp.Compiler.TypeChecker.MutRecBindingChecking.TcMutRecDefns_Phase2_Bindings(cenv cenv, TcEnv envInitial, SyntacticUnscopedTyparEnv tpenv, range bindsm, range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRecPrelimWithReprs, FSharpList`1 mutRecDefns)
   at FSharp.Compiler.TypeChecker.TcMutRecDefns_Phase2(cenv cenv, TcEnv envInitial, range bindsm, range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRec, FSharpList`1 mutRecDefns)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcMutRecDefns_Phase2(cenv cenv, TcEnv envInitial, range bindsm, range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRec, FSharpList`1 mutRecDefns)
   at FSharp.Compiler.TypeChecker.TcDeclarations.TcMutRecDefinitions(cenv cenv, TcEnv envInitial, ParentRef parent, FSharpSet`1 typeNames, SyntacticUnscopedTyparEnv tpenv, range m, range scopem, FSharpOption`1 mutRecNSInfo, FSharpList`1 mutRecDefns)
   at FSharp.Compiler.TypeChecker.TcModuleOrNamespaceElementNonMutRec@17137-1.Invoke(Unit unitVar)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.catch@912-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcModuleOrNamespaceElementNonMutRec@17136-19.Invoke(Exception _arg3)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.catch@912-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcModuleOrNamespaceElementNonMutRec@17136-19.Invoke(Exception _arg3)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.catch@912-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcModuleOrNamespaceElementNonMutRec@17136-19.Invoke(Exception _arg3)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.catch@912-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.TypeChecker.TcModuleOrNamespaceElementNonMutRec@17136-19.Invoke(Exception _arg3)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.bind@903-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.catch@912-1.Invoke(CompilationThreadToken ctok)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.CompileOps.TypeCheckOneInputEventually@5427-8.Invoke(Exception _arg4)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.forceWhile[a](CompilationThreadToken ctok, FSharpFunc`2 check, Eventually`1 e)
   at FSharp.Compiler.AbstractIL.Internal.Library.EventuallyModule.force[a](CompilationThreadToken ctok, Eventually`1 e)
   at FSharp.Compiler.CompileOps.TypeCheckOneInput(CompilationThreadToken ctok, FSharpFunc`2 checkForErrors, TcConfig tcConfig, TcImports tcImports, TcGlobals tcGlobals, FSharpOption`1 prefixPathOpt, TcState tcState, ParsedInput inp)
   at [email protected](TcState tcState, ParsedInput inp)
   at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, FSharpList`1 xs)
   at FSharp.Compiler.CompileOps.TypeCheckClosedInputSet(CompilationThreadToken ctok, FSharpFunc`2 checkForErrors, TcConfig tcConfig, TcImports tcImports, TcGlobals tcGlobals, FSharpOption`1 prefixPathOpt, TcState tcState, FSharpList`1 inputs)
   at FSharp.Compiler.Driver.TypeCheck(CompilationThreadToken ctok, TcConfig tcConfig, TcImports tcImports, TcGlobals tcGlobals, ErrorLogger errorLogger, String assemblyName, NiceNameGenerator niceNameGen, TcEnv tcEnv0, FSharpList`1 inputs, Exiter exiter)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.Driver.TypeCheck(CompilationThreadToken ctok, TcConfig tcConfig, TcImports tcImports, TcGlobals tcGlobals, ErrorLogger errorLogger, String assemblyName, NiceNameGenerator niceNameGen, TcEnv tcEnv0, FSharpList`1 inputs, Exiter exiter)
   at FSharp.Compiler.Driver.main0[a](a ctok, String[] argv, Resolver legacyReferenceResolver, Boolean bannerAlreadyPrinted, ReduceMemoryFlag reduceMemoryUsage, CopyFSharpCoreFlag defaultCopyFSharpCore, Exiter exiter, ErrorLoggerProvider errorLoggerProvider, DisposablesTracker disposables)
   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)         at FSharp.Compiler.CommandLineMain.Driver.main(String[] argv)
   at FSharp.Compiler.CommandLineMain.main(String[] argv)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ReraiseIfWatsonable(Exception exn)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.ErrorRecovery(ErrorLogger x, Exception exn, range m)
   at FSharp.Compiler.CommandLineMain.main(String[] argv)

Known workarounds

Don't forget the Measure attribute!

Related information

Related information:

  • Operating system: Windows 10
  • .NET Runtime kind: .NET Framework
  • Editing Tools: Both Visual Studio 2019 and Visual Studio Code with Ionide show the same internal error via intellisense

BillHally avatar Sep 04 '19 11:09 BillHally