Skip to content

Conversation

@josevalim
Copy link
Member

@josevalim josevalim commented Dec 25, 2024

This pull request adds type checking of protocol implementations.

In other words, if you implement a protocol FooBar for a struct T, we will validate that the arguments given to the implementation are said structs. Here is an example:

Screenshot 2024-12-25 at 19 22 34

The to_charlist callback expects a URI struct, which does not have the .unknown field, and therefore a typing violation is reported. This will help ensure protocol implementations are kept in sync with struct definitions. In order to make this all work, we now warn when implementing a protocol for an undefined struct.

@josevalim josevalim merged commit 30764fe into main Dec 26, 2024
18 checks passed
@josevalim josevalim deleted the jv-type-check-impls branch December 26, 2024 08:00
@josevalim josevalim changed the title Add type checking of implementations Type checking of protocol implementations Dec 27, 2024
@zachdaniel
Copy link
Contributor

Wasn’t something done recently to ensure that using defimpl didn’t require a compile time dependency on modules specified on the module passed into the for option? Is that no longer the case with this change or does type checking like this happen in a later pass that doesn’t incur compile dependencies?

@josevalim
Copy link
Member Author

We still do not require a compile-time dependency. A later commit to main pushed a test too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants