Skip to content

Conversation

@rodiazet
Copy link
Collaborator

@rodiazet rodiazet commented Dec 8, 2025

This PR fixes a bug in implementation of accessing an event which is defined in a separated, imported contract.

Closes: #16314

@cameel cameel changed the title Fix emiting events imported from separeted contract and accessed via member access. Fix emiting events via member access Dec 8, 2025
Copy link
Collaborator

@cameel cameel Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a related error message in the parser that is missing events as well:

fatalParserError(7858_error, "Expected pragma, import directive or contract/interface/library/struct/enum/constant/function/error definition.");

It should also mention UDVTs, but I'd recommend just replacing "struct/enum" with a catch-all "user-defined type" instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more complete coverage, we should add other types of tests here:

And I suspect we're missing this coverage for imported errors as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I think ABI/AST tests are not multi-file but you can work around it by just having the file import itself as a module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No contract is being imported here. event_emit_from_module_via_member_access.sol would be a more accurate name.

Comment on lines +1 to +4
==== Source: a ====
event Transfer(address indexed _from, address indexed _to, uint256 _value);
==== Source: b ====
import * as Test2 from "a";
Copy link
Collaborator

@cameel cameel Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit clearer naming so that it's more obvious at a glance what is a file, what is a module, etc.

Suggested change
==== Source: a ====
event Transfer(address indexed _from, address indexed _to, uint256 _value);
==== Source: b ====
import * as Test2 from "a";
==== Source: A.sol ====
event Transfer(address indexed _from, address indexed _to, uint256 _value);
==== Source: B.sol ====
import * as M from "A.sol";


contract A {
function returnAddress() external {
emit Test2.Transfer(address(11), address(12), 13);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have coverage for the M.C.Transfer and M1.M2.Transfer cases (where C is a contract)?

And same for errors?

@cameel
Copy link
Collaborator

cameel commented Dec 8, 2025

event which is defined in a separated, imported contract.

Note that this technically does not have to be a separate file (and it's a file, not a contract). A file can import itself as a module.

@cameel
Copy link
Collaborator

cameel commented Dec 8, 2025

Also, this needs a changelog entry.

@cameel cameel changed the title Fix emiting events via member access Fix emitting events via member access Dec 8, 2025
@cameel cameel changed the title Fix emitting events via member access Fix emitting events via module member access Dec 8, 2025
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

Successfully merging this pull request may close these issues.

ICE when emitting an event via module member access

2 participants