Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit347b209

Browse files
committed
Fix FS104 incorrectly handling non-F# enum values
1 parentdf53015 commit347b209

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

‎src/fsharp/PatternMatchCompilation.fs‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module internal Microsoft.FSharp.Compiler.PatternMatchCompilation
44

55
openSystem.Collections.Generic
66
openMicrosoft.FSharp.Compiler
7+
openMicrosoft.FSharp.Compiler.AbstractIL.IL
78
openMicrosoft.FSharp.Compiler.AbstractIL.Internal.Library
89
openMicrosoft.FSharp.Compiler.AbstractIL.Diagnostics
910
openMicrosoft.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+
letTcFieldInit 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->
239258
match tryDestAppTy g tywith
240259
| Some tcrefwhen tcref.IsEnumTycon->
241-
// search for an enum value that pattern match (consts) does not contain
242-
letnonCoveredEnumValues=
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+
letenumValues=
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+
letnonCoveredEnumValues= Seq.tryFind(fun(_,fldValue)->not(consts.Contains fldValue)) enumValues
276+
247277
match nonCoveredEnumValueswith
248278
| None-> Expr.Const(c,m,ty),true
249-
| Somef->
250-
letv= RecdFieldRef.RFRef(tcref,f.rfield_id.idText)
279+
| Some(fldName,_)->
280+
letv= RecdFieldRef.RFRef(tcref,fldName)
251281
Expr.Op(TOp.ValFieldGet v,[ty],[], m),false
252282
|_-> Expr.Const(c,m,ty),false
253283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp