|
| 1 | +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. |
| 2 | + |
| 3 | +namespace EmittedIL |
| 4 | + |
| 5 | +open Xunit |
| 6 | +open FSharp.Test |
| 7 | +open FSharp.Test.Compiler |
| 8 | +open FSharp.Test.Utilities |
| 9 | + |
| 10 | +module CodeGenRegressions_TypeDefs = |
| 11 | + |
| 12 | + let private getActualIL (result: CompilationResult) = |
| 13 | + match result with |
| 14 | + | CompilationResult.Success s -> |
| 15 | + match s.OutputPath with |
| 16 | + | Some p -> |
| 17 | + let (_, _, actualIL) = ILChecker.verifyILAndReturnActual [] p [ "// dummy" ] |
| 18 | + actualIL |
| 19 | + | None -> failwith "No output path" |
| 20 | + | _ -> failwith "Compilation failed" |
| 21 | + |
| 22 | + // https://github.com/dotnet/fsharp/issues/16565 |
| 23 | + [<Fact>] |
| 24 | + let ``Issue_16565_DefaultAugmentationFalseDuplicateEntry`` () = |
| 25 | + let source = """ |
| 26 | +module Test |
| 27 | +
|
| 28 | +open System |
| 29 | +
|
| 30 | +[<DefaultAugmentation(false)>] |
| 31 | +type Option<'T> = |
| 32 | + | Some of Value: 'T |
| 33 | + | None |
| 34 | +
|
| 35 | + member x.Value = |
| 36 | + match x with |
| 37 | + | Some x -> x |
| 38 | + | None -> raise (new InvalidOperationException("Option.Value")) |
| 39 | +
|
| 40 | + static member None : Option<'T> = None |
| 41 | +
|
| 42 | +and 'T option = Option<'T> |
| 43 | +
|
| 44 | +let v = Option.Some 42 |
| 45 | +printfn "Value: %d" v.Value |
| 46 | +let n = Option<int>.None |
| 47 | +printfn "None created successfully" |
| 48 | +""" |
| 49 | + FSharp source |
| 50 | + |> asExe |
| 51 | + |> compile |
| 52 | + |> shouldSucceed |
| 53 | + |> run |
| 54 | + |> shouldSucceed |
| 55 | + |> ignore |
| 56 | + |
| 57 | + // https://github.com/dotnet/fsharp/issues/14321 |
| 58 | + [<Fact>] |
| 59 | + let ``Issue_14321_DuAndIWSAMNames`` () = |
| 60 | + let source = """ |
| 61 | +module Test |
| 62 | +
|
| 63 | +#nowarn "3535" // IWSAM warning |
| 64 | +
|
| 65 | +type EngineError<'e> = |
| 66 | + static abstract Overheated : 'e |
| 67 | + static abstract LowOil : 'e |
| 68 | +
|
| 69 | +type CarError = |
| 70 | + | Overheated |
| 71 | + | LowOil |
| 72 | + | DeviceNotPaired |
| 73 | +
|
| 74 | + interface EngineError<CarError> with |
| 75 | + static member Overheated = Overheated |
| 76 | + static member LowOil = LowOil |
| 77 | +""" |
| 78 | + FSharp source |
| 79 | + |> asLibrary |
| 80 | + |> compile |
| 81 | + |> shouldSucceed |
| 82 | + |> ignore |
| 83 | + |
| 84 | + // https://github.com/dotnet/fsharp/issues/14321 |
| 85 | + // Runtime test: type must load without "duplicate entry in method table" |
| 86 | + [<Fact>] |
| 87 | + let ``Issue_14321_DuAndIWSAMNames_Runtime`` () = |
| 88 | + let source = """ |
| 89 | +module Test |
| 90 | +
|
| 91 | +#nowarn "3535" |
| 92 | +
|
| 93 | +type EngineError<'e> = |
| 94 | + static abstract Overheated : 'e |
| 95 | + static abstract LowOil : 'e |
| 96 | +
|
| 97 | +type CarError = |
| 98 | + | Overheated |
| 99 | + | LowOil |
| 100 | + | DeviceNotPaired |
| 101 | +
|
| 102 | + interface EngineError<CarError> with |
| 103 | + static member Overheated = Overheated |
| 104 | + static member LowOil = LowOil |
| 105 | +
|
| 106 | +[<EntryPoint>] |
| 107 | +let main _ = |
| 108 | + let err = CarError.Overheated |
| 109 | + match err with |
| 110 | + | Overheated -> printfn "Got Overheated" |
| 111 | + | LowOil -> printfn "Got LowOil" |
| 112 | + | DeviceNotPaired -> printfn "Got DeviceNotPaired" |
| 113 | + 0 |
| 114 | +""" |
| 115 | + FSharp source |
| 116 | + |> asExe |
| 117 | + |> compile |
| 118 | + |> shouldSucceed |
| 119 | + |> run |
| 120 | + |> shouldSucceed |
| 121 | + |> ignore |
| 122 | + |
| 123 | + // https://github.com/dotnet/fsharp/issues/5834 |
| 124 | + [<Fact>] |
| 125 | + let ``Issue_5834_EventSpecialname`` () = |
| 126 | + let source = """ |
| 127 | +module Test |
| 128 | +
|
| 129 | +open System |
| 130 | +open System.Reflection |
| 131 | +
|
| 132 | +type IAbstract1 = |
| 133 | + [<CLIEvent>] |
| 134 | + abstract member Event : IEvent<EventHandler, EventArgs> |
| 135 | +
|
| 136 | +type IAbstract2 = |
| 137 | + [<CLIEvent>] |
| 138 | + abstract member Event : IDelegateEvent<EventHandler> |
| 139 | +
|
| 140 | +[<AbstractClass>] |
| 141 | +type Abstract3() = |
| 142 | + [<CLIEvent>] |
| 143 | + abstract member Event : IDelegateEvent<EventHandler> |
| 144 | +
|
| 145 | +type Concrete1() = |
| 146 | + let event = new Event<EventHandler, EventArgs>() |
| 147 | + [<CLIEvent>] |
| 148 | + member this.Event = event.Publish |
| 149 | +
|
| 150 | +type Concrete2() = |
| 151 | + [<CLIEvent>] |
| 152 | + member this.Event = { new IDelegateEvent<EventHandler> with |
| 153 | + member this.AddHandler _ = () |
| 154 | + member this.RemoveHandler _ = () } |
| 155 | +
|
| 156 | +type ConcreteWithObsolete() = |
| 157 | + let evt = new Event<EventHandler, EventArgs>() |
| 158 | + [<Obsolete("deprecated")>] |
| 159 | + [<CLIEvent>] |
| 160 | + member this.MyEvent = evt.Publish |
| 161 | +
|
| 162 | +[<EntryPoint>] |
| 163 | +let main _ = |
| 164 | + let mutable failures = 0 |
| 165 | + let check (t: Type) = |
| 166 | + t.GetMethods(BindingFlags.Public ||| BindingFlags.Instance ||| BindingFlags.DeclaredOnly) |
| 167 | + |> Array.filter (fun m -> m.Name.Contains("Event")) |
| 168 | + |> Array.iter (fun m -> |
| 169 | + if not m.IsSpecialName then |
| 170 | + printfn "FAIL: %s.%s missing specialname" t.Name m.Name |
| 171 | + failures <- failures + 1) |
| 172 | +
|
| 173 | + check typeof<IAbstract1> |
| 174 | + check typeof<IAbstract2> |
| 175 | + check typeof<Abstract3> |
| 176 | + check typeof<Concrete1> |
| 177 | + check typeof<Concrete2> |
| 178 | + check typeof<ConcreteWithObsolete> |
| 179 | +
|
| 180 | + if failures > 0 then |
| 181 | + failwithf "BUG: %d event accessors missing specialname" failures |
| 182 | + printfn "SUCCESS: All event accessors have specialname" |
| 183 | + 0 |
| 184 | +""" |
| 185 | + FSharp source |
| 186 | + |> asExe |
| 187 | + |> compile |
| 188 | + |> shouldSucceed |
| 189 | + |> run |
| 190 | + |> shouldSucceed |
| 191 | + |> ignore |
| 192 | + |
0 commit comments