spicy
spicy copied to clipboard
"print" on a method produces illegal C++ code
module Issue_462_write_should_be_considered_a_rsved_word;
import spicy;
public type A = unit {
on %init { self.b.connect(new B); }
write: uint8;
connect: bytes &size=self.write { self.b.write($$); }
on %done { print "B.write", self.b.write;
print "B.write", self.b.connect; }
sink b;
};
public type B = unit {
write: /GET /;
connect: /[^\n]+/;
on %done { print "B", self; }
};
encounters syntactic probems:
printf '\13GET /a/b/c\n' | submod/spicy/build/bin/spicy-driver Issue_462_write_rsved_word.spicy -p Issue_462_write_should_be_considered_a_rsved_word::A
Issue_462_write_should_be_considered_a_rsved_word.cc:439:83: error: reference to non-static member function must be called
hilti::rt::printValues(std::make_tuple(std::string("B.write"), (*(*__self).b).write), true);
~~~~~~~~~~~~~~~^~~~~
Issue_462_write_should_be_considered_a_rsved_word.cc:440:83: error: reference to non-static member function must be called
hilti::rt::printValues(std::make_tuple(std::string("B.write"), (*(*__self).b).connect), true);
~~~~~~~~~~~~~~~^~~~~~~
/usr/local/etc/tmp/submod/spicy/spicy/include/spicy/rt/sink.h:123:10: note: possible target for call
void connect(spicy::rt::UnitRef<T> unit) {
^
2 errors generated.
[error] jit: failed to execute compilation action.
[error] jit: failed to compile C++ code unit Issue_462_write_should_be_considered_a_rsved_word to bitcode
[error] spicy-driver: aborting after errors
In comparison, a version with those member names, but without the print attempts, does succeed:
module Issue_462_write_should_be_considered_a_rsved_word;
import spicy;
public type A = unit {
on %init { self.b.connect(new B); }
write: uint8;
connect: bytes &size=self.write { self.b.write($$); }
on %done { print "A", self; }
sink b;
};
public type B = unit {
write: /GET /;
connect: /[^\n]+/;
on %done { print "B", self; }
};
outputting:
printf '\13GET /a/b/c\n' | submod/spicy/build/bin/spicy-driver Issue_462_wo_print.spicy -p Issue_462_write_should_be_considered_a_rsved_word::A
B, [$write=b"GET ", $connect=b"/a/b/c"]
A, [$write=11, $connect=b"GET /a/b/c\n", $b=<sink>]
The print is not needed, even just a tuple-ization triggers the error:
module Issue_462_write_should_be_considered_a_rsved_word;
import spicy;
public type A = unit {
on %init { self.b.connect(new B); }
var makeAtuple: tuple<string>;
write: uint8;
connect: bytes &size=self.write { self.b.write($$); }
on %done { print "A", self;
self.makeAtuple = ("%s" % (self.write,),);
self.makeAtuple = ("%s" % (self.b.write,),); }
sink b;
};
public type B = unit {
write: /GET /;
connect: /[^\n]+/;
on %done { print "B", self; }
};
printf '\13GET /a/b/c\n' | submod/spicy/build/bin/spicy-driver Issue_462_make_tuple.spicy -p Issue_462_write_should_be_considered_a_rsved_word::A
Issue_462_write_should_be_considered_a_rsved_word.cc:443:93: error: reference to non-static member function must be called
(*__self).makeAtuple = std::make_tuple(hilti::rt::fmt(std::string("%s"), (*(*__self).b).write));
~~~~~~~~~~~~~~~^~~~~
1 error generated.
[error] jit: failed to execute compilation action.
[error] jit: failed to compile C++ code unit Issue_462_write_should_be_considered_a_rsved_word to bitcode
Oh, nevermind. The reported syntax error is because sink b; declaration isn't capable of accessing the members of b. I now see that
module Issue_462_C_not_B;
import spicy;
public type A = unit {
on %init { self.b.connect(new B); }
write: uint8;
connect: bytes &size=self.write { self.b.write($$); }
on %done { print "C.write", self.c.write;
print "C.connect", self.c.connect; }
sink b;
c: B;
};
public type B = unit {
write: /GET /;
connect: /[^\n]+/;
on %done { print "B", self; }
};
produces:
printf '\13GET /a/b/c\13GET /a/b/c\n' | submod/spicy/build/bin/spicy-driver Issue_462_C_not_B.spicy -p Issue_462_C_not_B::A
B, [$write=b"GET ", $connect=b"/a/b/c\x0b"]
B, [$write=b"GET ", $connect=b"/a/b/c"]
C.write, GET
C.connect, /a/b/c
Was this supposed to be caught in Spicy, or is it fine that the diagnostic is first reported in:
[error] jit: failed to execute compilation action.
I reopened after confirming that .write is being treated differently.
module Issue_467_missing_member_named_self;
import spicy;
public type A = unit {
on %init { self.b.connect(new B); }
length: uint8;
data: bytes &size=self.length { self.b.write($$); }
on %done { print "A", self;
# print "B", self.b.isThere;
print "B", self.b.write; }
sink b;
};
public type B = unit {
var isThere: bool;
cmd: /GET /;
path: /[^\n]+/;
on %done { print "B", self; }
};
produces
printf '\12GET ABCDE\12GET ABCDE\n' | ./spicy/build/bin/spicy-driver /usr/local/etc/tmp/Issue_467_missing_member_named_self.spicy -p Issue_467_missing_member_named_self::A
Issue_467_missing_member_named_self.cc:473:77: error: reference to non-static member function must be called
hilti::rt::printValues(std::make_tuple(std::string("B"), (*(*__self).b).write), true);
~~~~~~~~~~~~~~~^~~~~
1 error generated.
[error] jit: failed to execute compilation action.
[error] jit: failed to compile C++ code unit Issue_467_missing_member_named_self to bitcode
[error] spicy-driver: aborting after errors
vs when I uncommented the attempt to access member .isThere (also when trying a non-member such as .isNotThere) then spicy syntax checking does catch that through the sink b, those are inaccessible:
printf '\12GET ABCDE\12GET ABCDE\n' | ./spicy/build/bin/spicy-driver /usr/local/etc/tmp/Issue_467_missing_member_named_self.spicy -p Issue_467_missing_member_named_self::A
[error] /usr/local/etc/tmp/Issue_467_missing_member_named_self.spicy:11: type does not have field 'isThere'
[error] spicy-driver: aborting after errors
It's a problem with printing a method, it's not about reserved words. Renaming ticket.