[Swift-devel] strange behavior evaluating function call as trace arg

Ben Clifford benc at hawaga.org.uk
Thu Feb 5 09:31:09 CST 2009


On Wed, 4 Feb 2009, Michael Wilde wrote:

> trace(add(123,456));

> Could not compile SwiftScript source: line 13:1: unexpected token: trace

related to this, there's a bug open related to syntax error - bug 173:

http://bugzilla.mcs.anl.gov/swift/show_bug.cgi?id=173

The syntax error should be reporting that add is not valid there, not that 
trace is an unexpected token.

This comes, I think, from deciding whether a statement is a procedure 
declaration or a procedure call by attempting to parse the entire first 
bit up to this:

  foo (syntactically valid argument declarations) {

or

  foo (syntactically valid argument expressions) ;

to distinguish between declarations or invocations.

In the case above, your statement matches neither of the above and so it 
tries to parse neither as a declaration or an invocation, giving an overly 
general error message saying, essentially, "i don't know what this whole 
statement is".

It may be possible to make better predictors or otherwise tighten up the 
location, but I had trouble last time. Having had a year to think about 
it, I may be able to come up with something better.

-- 



More information about the Swift-devel mailing list