Skip to content

Commit

Permalink
Stop usage of ~ in function arguments and as a local variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Jan 6, 2017
1 parent f1ce770 commit e3650d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,9 @@ struct ArgList ReadFuncArgList(
SET_LEN_STRING(locks, 1);
GetSymbol();
}
if ( strcmp("~", TLS(Value)) == 0 ) {
SyntaxError("~ is not a valid name for an argument");
}
C_NEW_STRING_DYN( name, TLS(Value) );
narg += 1;
ASS_LIST( nams, narg, name );
Expand Down Expand Up @@ -1367,6 +1370,9 @@ struct ArgList ReadFuncArgList(
SyntaxError("Name used for two arguments");
}
}
if ( strcmp("~", TLS(Value)) == 0 ) {
SyntaxError("~ is not a valid name for an argument");
}
C_NEW_STRING_DYN( name, TLS(Value) );
narg += 1;
ASS_LIST( nams, narg, name );
Expand Down Expand Up @@ -1452,6 +1458,9 @@ void ReadFuncExpr (
SyntaxError("Name used for argument and local");
}
}
if ( strcmp("~", TLS(Value)) == 0 ) {
SyntaxError("~ is not a valid name for a local identifier");
}
C_NEW_STRING_DYN( name, TLS(Value) );
nloc += 1;
ASS_LIST( nams, narg+nloc, name );
Expand All @@ -1470,6 +1479,9 @@ void ReadFuncExpr (
SyntaxError("Name used for two locals");
}
}
if ( strcmp("~", TLS(Value)) == 0 ) {
SyntaxError("~ is not a valid name for a local identifier");
}
C_NEW_STRING_DYN( name, TLS(Value) );
nloc += 1;
ASS_LIST( nams, narg+nloc, name );
Expand Down
28 changes: 28 additions & 0 deletions tst/testinstall/tilde.tst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,32 @@ gap> r.x;
rec( x := ~, y := [ 1, 2, ~ ] )
gap> r.y[3];
rec( x := ~, y := [ 1, 2, ~ ] )
gap> f := function(~) local a; end;
Syntax error: ~ is not a valid name for an argument in stream:1
f := function(~) local a; end;
^
gap> f := function(a,~) local a; end;
Syntax error: ~ is not a valid name for an argument in stream:1
f := function(a,~) local a; end;
^
gap> f := function(a,b) local ~; end;
Syntax error: ~ is not a valid name for a local identifier in stream:1
f := function(a,b) local ~; end;
^
gap> f := function(a,b) local x,~; end;
Syntax error: ~ is not a valid name for a local identifier in stream:1
f := function(a,b) local x,~; end;
^
gap> {~} -> ~;
Syntax error: ~ is not a valid name for an argument in stream:1
{~} -> ~;
^
gap> {~,~} -> 2;
Syntax error: ~ is not a valid name for an argument in stream:1
{~,~} -> 2;
^
gap> ({} -> ~);
function( ) ... end
gap> ({} -> ~)();
Error, Variable: '~' must have an assigned value
gap> STOP_TEST( "tilde.tst", 1);

0 comments on commit e3650d1

Please sign in to comment.