diff options
-rw-r--r-- | compiler/ngtcon.pas | 43 | ||||
-rw-r--r-- | tests/webtbs/tw25602.pp | 26 |
2 files changed, 57 insertions, 12 deletions
diff --git a/compiler/ngtcon.pas b/compiler/ngtcon.pas index 71a5b0d184..eb3cf8a46e 100644 --- a/compiler/ngtcon.pas +++ b/compiler/ngtcon.pas @@ -1109,21 +1109,40 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis begin oldoffset:=curoffset; curoffset:=0; - for i:=def.lowrange to def.highrange-1 do + { in case of a generic subroutine, it might be we cannot + determine the size yet } + if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) then begin - read_typed_const_data(def.elementdef); - Inc(curoffset,def.elementdef.size); - if token=_RKLAMMER then + while true do begin - Message1(parser_e_more_array_elements_expected,tostr(def.highrange-i)); - consume(_RKLAMMER); - exit; - end - else - consume(_COMMA); + read_typed_const_data(def.elementdef); + if token=_RKLAMMER then + begin + consume(_RKLAMMER); + break; + end + else + consume(_COMMA); + end; + end + else + begin + for i:=def.lowrange to def.highrange-1 do + begin + read_typed_const_data(def.elementdef); + Inc(curoffset,def.elementdef.size); + if token=_RKLAMMER then + begin + Message1(parser_e_more_array_elements_expected,tostr(def.highrange-i)); + consume(_RKLAMMER); + exit; + end + else + consume(_COMMA); + end; + read_typed_const_data(def.elementdef); + consume(_RKLAMMER); end; - read_typed_const_data(def.elementdef); - consume(_RKLAMMER); curoffset:=oldoffset; end { if array of char then we allow also a string } diff --git a/tests/webtbs/tw25602.pp b/tests/webtbs/tw25602.pp new file mode 100644 index 0000000000..0fbc51cb94 --- /dev/null +++ b/tests/webtbs/tw25602.pp @@ -0,0 +1,26 @@ +{$MODE DELPHI} + +type + TA = class + const C = 1; + end; + + TB<T> = object + procedure Foo; + end; + +procedure TB<T>.Foo; +var + // X: array[0..T.C] of byte = (0); // Error: Expected another 1 array elements + X: array[0..T.C] of byte = (0, 2); // Fatal: Syntax error, ")" expected but "," found +begin + if high(x)<>1 then + halt(1); + writeln('ok'); +end; + +var + x: TB<TA>; +begin + x.Foo; +end. |