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

Commitd7f1358

Browse files
dsymeKevinRansom
authored andcommitted
Fix failure where a struct union doesn't compile (#3274)
1 parenta2ef90a commitd7f1358

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

‎src/ilx/EraseUnions.fs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ let rec extraTysAndInstrsForStructCtor (ilg: ILGlobals) cidx =
318318
lettys,instrs= extraTysAndInstrsForStructCtor ilg(cidx-7)
319319
(ilg.typ_UInt32:: tys, mkLdcInt320:: instrs)
320320

321+
lettakesExtraParams(alts:IlxUnionAlternative[])=
322+
alts.Length>1&&
323+
(alts|> Array.exists(fun d-> d.FieldDefs.Length>0)||
324+
// Check if not all lengths are distinct
325+
alts|> Array.countBy(fun d-> d.FieldDefs.Length)|> Array.length<> alts.Length)
326+
321327
letconvNewDataInstrInternal ilg cuspec cidx=
322328
letalt= altOfUnionSpec cuspec cidx
323329
letaltTy= tyForAlt cuspec alt
@@ -344,7 +350,7 @@ let convNewDataInstrInternal ilg cuspec cidx =
344350
|_->[],[]
345351
letctorFieldTys= alt.FieldTypes|> Array.toList
346352
letextraTys,extraInstrs=
347-
ifcuspec.AlternativesArray.Length>1&&cuspec.AlternativesArray|> Array.exists(fun d-> d.FieldDefs.Length>0)then
353+
iftakesExtraParamscuspec.AlternativesArraythen
348354
extraTysAndInstrsForStructCtor ilg cidx
349355
else
350356
[],[]
@@ -949,7 +955,7 @@ let mkClassUnionDef (addMethodGeneratedAttrs, addPropertyGeneratedAttrs, addProp
949955
| Some typ-> Some typ.TypeSpec
950956

951957
letextraParamsForCtor=
952-
if isStruct&&cud.cudAlternatives.Length>1&&cud.cudAlternatives|> Array.exists(fun d-> d.FieldDefs.Length>0)then
958+
if isStruct&&takesExtraParamscud.cudAlternativesthen
953959
letextraTys,_extraInstrs= extraTysAndInstrsForStructCtor ilg cidx
954960
List.map mkILParamAnon extraTys
955961
else

‎tests/fsharp/core/members/basics/test.fs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,20 @@ module OverrideIComparableOnUnionTest = begin
11121112
do testc s4 s2
11131113
end
11141114

1115+
moduleTwoCaseUnionTest=
1116+
1117+
[<Struct>]
1118+
typeMyUnion= A| B
1119+
1120+
do test"union-TwoCaseUnionTest-def"(A<> B)
1121+
do test"union-TwoCaseUnionTest-def"(A= A)
1122+
do test"union-TwoCaseUnionTest-def"(B= B)
1123+
do test"union-TwoCaseUnionTest-def"(B> A)
1124+
do test"union-TwoCaseUnionTest-def"(A< B)
1125+
do test"union-TwoCaseUnionTest-def"(A<= B)
1126+
do test"union-TwoCaseUnionTest-def"(B>= A)
1127+
1128+
11151129
moduleToStringOnUnionTest=begin
11161130

11171131
typeMyUnion= Aofstring| B

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp