* use the parsed node type for checking the validity of default parameter

values instead of a default based on the resulting constsym (more robust)

git-svn-id: trunk@22267 -
This commit is contained in:
Jonas Maebe 2012-08-29 16:09:13 +00:00
parent ad054831bb
commit 01b5e2b6f6
2 changed files with 6 additions and 10 deletions

View File

@ -35,7 +35,7 @@ interface
{ pass_1 }
node;
function readconstant(const orgname:string;const filepos:tfileposinfo):tconstsym;
function readconstant(const orgname:string;const filepos:tfileposinfo; out nodetype: tnodetype):tconstsym;
procedure const_dec;
procedure consts_dec(in_structure, allow_typed_const: boolean);
@ -76,7 +76,7 @@ implementation
;
function readconstant(const orgname:string;const filepos:tfileposinfo):tconstsym;
function readconstant(const orgname:string;const filepos:tfileposinfo; out nodetype: tnodetype):tconstsym;
var
hp : tconstsym;
p : tnode;
@ -92,6 +92,7 @@ implementation
internalerror(9584582);
hp:=nil;
p:=comp_expr(true,false);
nodetype:=p.nodetype;
storetokenpos:=current_tokenpos;
current_tokenpos:=filepos;
case p.nodetype of
@ -194,6 +195,7 @@ implementation
dummysymoptions : tsymoptions;
deprecatedmsg : pshortstring;
storetokenpos,filepos : tfileposinfo;
nodetype : tnodetype;
old_block_type : tblock_type;
skipequal : boolean;
tclist : tasmlist;
@ -210,7 +212,7 @@ implementation
_EQ:
begin
consume(_EQ);
sym:=readconstant(orgname,filepos);
sym:=readconstant(orgname,filepos,nodetype);
{ Support hint directives }
dummysymoptions:=[];
deprecatedmsg:=nil;

View File

@ -256,7 +256,7 @@ implementation
bt:=block_type;
block_type:=bt_const;
{ prefix 'def' to the parameter name }
defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo,nodetype);
block_type:=bt;
if assigned(defaultvalue) then
begin
@ -264,12 +264,6 @@ implementation
pd.parast.insert(defaultvalue);
{ check whether the default value is of the correct
type }
if defaultvalue.consttyp in [conststring,constwstring] then
nodetype:=stringconstn
else if defaultvalue.consttyp=constnil then
nodetype:=niln
else
nodetype:=nothingn;
if compare_defs_ext(defaultvalue.constdef,hdef,nodetype,doconv,convpd,[])<=te_convert_operator then
MessagePos2(defaultvalue.fileinfo,type_e_incompatible_types,FullTypeName(defaultvalue.constdef,hdef),FullTypeName(hdef,defaultvalue.constdef));
end;