fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Infinite loop on expanding cycle for struct types

Open TIHan opened this issue 7 years ago • 4 comments

[<Struct>]
type MyStruct<'T> =

    val field : YourStruct<MyStruct<MyStruct<'T>>>

and [<Struct>] YourStruct<'T> =

    val field : 'T

If you define this in F#, it will cause an infinite loop in the compiler and you will have to kill your process for it to stop.

We expect to receive an error when defining this type.

TIHan avatar Jan 09 '19 01:01 TIHan

Nice catch. There's code to catch this sort of thing an it catches a lot of cases but it's surprisingly hard to get right!

dsyme avatar Jan 09 '19 15:01 dsyme

How did you find this one?

dsyme avatar Jan 09 '19 15:01 dsyme

@RikkiGibson had a test case for C#, and I tried in F# and we blew up :)

TIHan avatar Jan 10 '19 00:01 TIHan

One weird trick discovered by a type theorist—compiler devs hate him!

RikkiGibson avatar Jan 10 '19 00:01 RikkiGibson