Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

The following code prevents the compiler from terminating #401

@LukaHorvat

Description

@LukaHorvat
type Switcher = Switcher

let inline checker< ^s, ^r when (^s or ^r) : (static member pass : ^r -> unit)> (s : ^s) (r : ^r) = ()

let inline format () : ^r =
    checker Switcher Unchecked.defaultof< ^r>
    () :> obj :?> ^r

type Switcher with
    static member inline pass(_ : string -> ^r) =
        checker Switcher Unchecked.defaultof< ^r>
    static member inline pass(_ : int -> ^r) =
        checker Switcher Unchecked.defaultof< ^r>
    static member inline pass(_ : unit) = ()
    static member inline pass(_ : int) = ()

[<EntryPoint>]
let main argv = 
    let res : unit = format () "text" 5 "more text" ()
    printfn "%A" res
    Console.ReadKey()
    0 // return an integer exit code

The idea was to make a function format that can return any function which's type passes a static check. The functions that are valid take parameters (arbitrarily many) of type string or int and produce either a unit or an int.
Including the checker function in another function would make sure that the type parameter is a valid function type, which would then be constructed unsafely via reflection or similar and then finally casted to the appropriate target type.

Unfortunately, this code causes the compiler to hang indefinitely (or as far as my patience extended).
This might not be a bug if it's a design decision to allow non-termination, but I'd find that strange considering my code consists only of valid language constructs.

I'm using Visual Studio 2015 Preview, my project targets .NET Framework 4.5.3 and the runtime is F# 4.0 (FSharp.Core, 4.4.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions