Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhelpful error message when "&" missing in chain #1711

Closed
0xxon opened this issue Apr 4, 2024 · 1 comment
Closed

Unhelpful error message when "&" missing in chain #1711

0xxon opened this issue Apr 4, 2024 · 1 comment
Assignees

Comments

@0xxon
Copy link
Member

0xxon commented Apr 4, 2024

This might be exactly the same issue/solution as in #1710, but I am not entirely sure - so I just filed it separately.

module Test;

type Share = unit {
};

public type Message = unit {
  %context = Share;

	sink alertsink;

	on %init {
		self.alertsink.connect(new Alert(self.context()));
	}
};

# note - this will mostly be garbage because it is encrypted.
public type Alert = unit(sh: Share&) {
  alerts: Alert_message(sh)[];
};

type Alert_message = unit(sh: Share) {
  level: uint8; # &convert=AlertLevel($$);
  description: uint8; # &convert=AlertDescription($$);
};

Generates the following error message:

$ spicyz test.spicy -o test.hlto
[error] /Users/johanna/spicy-test/test.spicy:18:3-18:30: type expects value_ref<const Share> for parameter 1, but receives value_ref<const Share>
[error] <Spicy support for Zeek>: aborting after errors

Adding a "&" to the Alert_message Share parameter fixes that. That being said, as a secondary issue - I am not even sure why the "&"'s are required. Removing it from the Alert unit results in this, similar, error message:

[error] /Users/johanna/spicy-test/test.spicy:12:26-12:50: type expects value_ref<const Share> for parameter 1, but receives value_ref<const Share>
[error] <Spicy support for Zeek>: aborting after errors
@0xxon
Copy link
Member Author

0xxon commented Apr 4, 2024

Oh, in related things to this - doing inout instead of & results in this error message:

$spicyz test.spicy -o test.hlto
In file included from /private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:6:
In file included from /Users/johanna/zeek/install/include/hilti/rt/libhilti.h:12:
In file included from /Users/johanna/zeek/install/include/hilti/rt/context.h:12:
In file included from /Users/johanna/zeek/install/include/hilti/rt/fiber.h:19:
/Users/johanna/zeek/install/include/hilti/rt/types/reference.h:720:31: error: no matching conversion for functional-style cast from '__hlt::Test::Share' to '__hlt::Test::Alert'
    return StrongReference<T>(T(std::forward<Args>(args)...));
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:573:60: note: in instantiation of function template specialization 'hilti::rt::reference::make_strong<__hlt::Test::Alert, __hlt::Test::Share &>' requested here
    (*(*__self).alertsink).connect(::hilti::rt::reference::make_strong<__hlt::Test::Alert>((*(*__self).__context)));
                                                           ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:99:9: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'const Alert' for 1st argument
        Alert(const Alert&) = default;
        ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:100:9: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'Alert' for 1st argument
        Alert(Alert&&) = default;
        ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:176:19: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to '::hilti::rt::ValueReference<__hlt::Test::Share> &' for 1st argument
    inline Alert::Alert(::hilti::rt::ValueReference<__hlt::Test::Share>& __p_sh) : __p_sh(std::move(__p_sh)) {
                  ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:179:19: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'std::optional<std::optional< ::hilti::rt::Vector<__hlt::Test::Alert_message>>>' for 1st argument
    inline Alert::Alert(std::optional<std::optional<::hilti::rt::Vector<__hlt::Test::Alert_message>>> alerts) : Alert() {
                  ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:173:19: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    inline Alert::Alert() {
                  ^
1 error generated.
[error] <Spicy support for Zeek>: JIT compilation failed

Source:

module Test;

type Share = unit {
};

public type Message = unit {
  %context = Share;

	sink alertsink;

	on %init {
		self.alertsink.connect(new Alert(self.context()));
	}
};

# note - this will mostly be garbage because it is encrypted.
public type Alert = unit(inout sh: Share) {
  alerts: Alert_message(sh)[];
};

type Alert_message = unit(sh: Share) {
  level: uint8; # &convert=AlertLevel($$);
  description: uint8; # &convert=AlertDescription($$);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants