Skip to content

Generic use of member constraint solved to record field causes crash #238

Closed

Description

@drvink

The following program typechecks, but crashes.

#light "off"
#nowarn "62";;

open System

type hober<'a> = { foo : 'a }
type gromus<'a> = { foo : 'a }
type hoobler<'a>(arg : 'a) = class
  member __.foo = arg
end

let inline
  print_foo_memb<'a, 'b when
    ^a :         (member foo : 'b)
                >
    x =
  printfn "%A" (^a : (member foo : 'b) x)

[<EntryPoint>]
let main _ =
  let a : hober<_> = { foo=1 } in
  let b : gromus<_> = { foo="horp" } in
  let c = hoobler("durr") in
  // these are ok
  print_foo_memb<_, int> a;
  print_foo_memb<_, string> b;
  print_foo_memb<_, string> c;
  // these will cause a crash!
  print_foo_memb a;
  print_foo_memb b;
  // but it seems to only happen when the (unannotated) function is applied to
  // a record--classes are ok
  print_foo_memb c;
  0

On .NET:

Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'c:\users\msjp_000\documents\visual studio 2013\Projects\crashy\crashy\bin\Debug\crashy.exe'.

Additional information: The runtime has encountered a fatal error. The address of the error was at 0x72110237, on thread 0xd68. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

On Mono:

Unhandled Exception:
System.InvalidProgramException: Invalid IL code in Horp:main (string[]): IL_0082: callvirt  0x0a00000f

[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in Horp:main (string[]): IL_0082: callvirt  0x0a00000f

This is with both fsc 3.1 and fsharpc 3.1.

Activity

  1. latkin commented on Feb 19, 2015

    @latkin
    Contributor

    Repros for me in 4.0. The "bad" lines result in nonverifiable generated code with object type parameter in calls, instead of proper int or string.

  2. dsyme commented on May 9, 2015

    @dsyme
    Contributor

    Minified repro:

    type hober<'a> = { foo : 'a }
    let inline f x = box (^a : (member foo : 'b) x)
    let v = f { foo=1 } 
    
  3. changed the title [-]Polymorphic function with member constraint applied to record causes crash[/-] [+]Generic use of member constraint solved to record field causes crash[/+] on May 11, 2015
  4. added this to the VS 2015 milestone on May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions