Skip to content

Commit

Permalink
Support skipping explicit %done in external hooks.
Browse files Browse the repository at this point in the history
Assuming `Foo::X` is a unit type, these two are now equivalent:

    on Foo::X::%done   { }
    on Foo::X          { }

Addresses #1465.
  • Loading branch information
rsmmr committed Jul 5, 2023
1 parent c049eab commit cec63b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions spicy/toolchain/src/compiler/visitors/normalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,17 @@ struct Visitor : public hilti::visitor::PostOrder<void, Visitor> {

auto resolved = hilti::scope::lookupID<hilti::declaration::Type>(ns, p, "unit type");
if ( ! resolved ) {
p.node.addError(resolved.error());
return;
// Look up as a type directly. If found, add explicit `%done`.
resolved = hilti::scope::lookupID<hilti::declaration::Type>(h.id(), p, "unit type");
if ( resolved ) {
logChange(p.node, "adding explicit %done hook");
p.node.as<Hook>().setID(h.id() + ID("0x25_done"));
modified = true;
}
else {
p.node.addError(resolved.error());
return;
}
}

unit_type_ref = resolved->first->as<hilti::declaration::Type>().typeRef();
Expand Down
2 changes: 2 additions & 0 deletions tests/Baseline/spicy.types.unit.external-hooks-import/output
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
FOO init
FOO a, 1234
FOO b, 567890
FOO done 1
FOO done 2
2 changes: 2 additions & 0 deletions tests/spicy/types/unit/external-hooks-import.spicy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Mini;
on Mini::Foo::a { print "FOO a", self.a; }
on Mini::Foo::b { print "FOO b", self.b; }
on Mini::Foo::%init { print "FOO init"; }
on Mini::Foo::%done { print "FOO done 1"; }
on Mini::Foo { print "FOO done 2"; }

### @TEST-START-FILE mini.spicy

Expand Down

0 comments on commit cec63b6

Please sign in to comment.