Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
drvink opened this issue Feb 15, 2015 · 2 comments
Closed

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

drvink opened this issue Feb 15, 2015 · 2 comments
Labels
Milestone

Comments

@drvink
Copy link
Contributor

drvink commented Feb 15, 2015

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.

@latkin
Copy link
Contributor

latkin commented Feb 19, 2015

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.

@dsyme
Copy link
Contributor

dsyme commented May 9, 2015

Minified repro:

type hober<'a> = { foo : 'a }
let inline f x = box (^a : (member foo : 'b) x)
let v = f { foo=1 } 

@dsyme dsyme changed the title Polymorphic function with member constraint applied to record causes crash Generic use of member constraint solved to record field causes crash May 11, 2015
@dsyme dsyme closed this as completed in 647787a May 20, 2015
@latkin latkin added the fixed label May 20, 2015
@latkin latkin added this to the VS 2015 milestone May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants