@@ -4,6 +4,7 @@ module internal Microsoft.FSharp.Compiler.PatternMatchCompilation
44
55open System.Collections .Generic
66open Microsoft.FSharp .Compiler
7+ open Microsoft.FSharp .Compiler .AbstractIL .IL
78open Microsoft.FSharp .Compiler .AbstractIL .Internal .Library
89open Microsoft.FSharp .Compiler .AbstractIL .Diagnostics
910open Microsoft.FSharp .Compiler .Range
@@ -154,6 +155,24 @@ let rec pathEq p1 p2 =
154155| PathEmpty(_), PathEmpty(_) -> true
155156| _ -> false
156157
158+ //// (Temporarily copy-pasted from TypeChecker.fs)
159+ let TcFieldInit lit =
160+ match litwith
161+ | ILFieldInit.String s-> Const.String s
162+ | ILFieldInit.Null-> Const.Zero
163+ | ILFieldInit.Bool b-> Const.Bool b
164+ | ILFieldInit.Char c-> Const.Char( char( int c))
165+ | ILFieldInit.Int8 x-> Const.SByte x
166+ | ILFieldInit.Int16 x-> Const.Int16 x
167+ | ILFieldInit.Int32 x-> Const.Int32 x
168+ | ILFieldInit.Int64 x-> Const.Int64 x
169+ | ILFieldInit.UInt8 x-> Const.Byte x
170+ | ILFieldInit.UInt16 x-> Const.UInt16 x
171+ | ILFieldInit.UInt32 x-> Const.UInt32 x
172+ | ILFieldInit.UInt64 x-> Const.UInt64 x
173+ | ILFieldInit.Single f-> Const.Single f
174+ | ILFieldInit.Double f-> Const.Double f
175+
157176
158177//---------------------------------------------------------------------------
159178// Counter example generation
@@ -238,16 +257,27 @@ let RefuteDiscrimSet g m path discrims =
238257| Some c->
239258match tryDestAppTy g tywith
240259| Some tcrefwhen tcref.IsEnumTycon->
241- // search for an enum value that pattern match (consts) does not contain
242- let nonCoveredEnumValues =
243- tcref.AllFieldsArray|> Array.tryFind( fun f ->
244- match f.rfield_ constwith
245- | None-> false
246- | Some fieldValue-> ( not ( consts.Contains fieldValue)) && f.rfield_ static)
260+ let enumValues =
261+ if tcref.IsILEnumTyconthen
262+ let ( TILObjectReprData ( _ , _ , tdef )) = tcref.ILTyconInfo
263+ tdef.Fields.AsList
264+ |> Seq.choose( fun ilField ->
265+ if ilField.IsStaticthen
266+ ilField.LiteralValue|> Option.map( fun ilValue ->
267+ ilField.Name, TcFieldInit ilValue)
268+ else None)
269+ else
270+ tcref.AllFieldsArray|> Seq.choose( fun fsField ->
271+ match fsField.rfield_ const, fsField.rfield_ staticwith
272+ | Some fsFieldValue, true -> Some( fsField.rfield_ id.idText, fsFieldValue)
273+ | _ -> None)
274+
275+ let nonCoveredEnumValues = Seq.tryFind( fun ( _ , fldValue ) -> not ( consts.Contains fldValue)) enumValues
276+
247277match nonCoveredEnumValueswith
248278| None-> Expr.Const( c, m, ty), true
249- | Somef ->
250- let v = RecdFieldRef.RFRef( tcref, f.rfield _ id.idText )
279+ | Some( fldName , _) ->
280+ let v = RecdFieldRef.RFRef( tcref, fldName )
251281 Expr.Op( TOp.ValFieldGet v, [ ty], [], m), false
252282| _ -> Expr.Const( c, m, ty), false
253283