diff --git a/.gitattributes b/.gitattributes index d086c77db9..6233cef6b5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17805,6 +17805,7 @@ tests/webtbs/tw3768.pp svneol=native#text/plain tests/webtbs/tw3774.pp svneol=native#text/plain tests/webtbs/tw3777.pp svneol=native#text/plain tests/webtbs/tw3778.pp svneol=native#text/plain +tests/webtbs/tw37796.pp svneol=native#text/pascal tests/webtbs/tw3780.pp svneol=native#text/plain tests/webtbs/tw37806.pp svneol=native#text/pascal tests/webtbs/tw3782.pp svneol=native#text/plain diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index ebe33104bc..078cbb31d2 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -1781,6 +1781,7 @@ implementation mayberesettypeconvs; exit; end; + arrayconstructorn, setconstn, stringconstn, guidconstn : @@ -2082,6 +2083,7 @@ implementation (tstringdef(def_to).encoding=tstringdef(p.resultdef).encoding) then eq:=te_equal end; + formaldef, setdef : begin { set can also be a not yet converted array constructor } diff --git a/compiler/ncal.pas b/compiler/ncal.pas index f10f8dd30e..46950ef104 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -1205,6 +1205,13 @@ implementation (parasym.vardef.typ=setdef) then inserttypeconv(left,parasym.vardef); + { if an array constructor can be a set and it is passed to + a formaldef, a set must be passed, see also issue #37796 } + if (left.nodetype=arrayconstructorn) and + (parasym.vardef.typ=formaldef) and + (arrayconstructor_can_be_set(left)) then + left:=arrayconstructor_to_set(left,false); + { set some settings needed for arrayconstructor } if is_array_constructor(left.resultdef) then begin diff --git a/tests/webtbs/tw37796.pp b/tests/webtbs/tw37796.pp new file mode 100644 index 0000000000..98aa6f93a9 --- /dev/null +++ b/tests/webtbs/tw37796.pp @@ -0,0 +1,38 @@ +program tformal; +{$mode objfpc} + +uses + sysutils; + +type + TFontStyle = ( + fsItalic, + fsBold, + fsUnderlined, + fsStrikeOut + ); + TFontStyles = set of TFontStyle; + +var aFS: TFontStyles; + +procedure Any(const Anything); +begin + aFS:=aFS+TFontStyles(Anything); + Writeln(IntToHex(PLongInt(@Anything)^, 8)); +end; + +procedure DoIt; +begin + Any([fsItalic, fsBold]); //unit1.pas(31,25) Error: Variable identifier expected + if aFS<>[fsItalic, fsBold] then + halt(1); + Any(Cardinal([fsItalic, fsBold])); //ok +end; + +begin + aFS:=[]; + writeln(Cardinal(aFS)); + DoIt; + writeln(Cardinal(aFS)); + writeln('ok'); +end.