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

Annotation of implements is not properly type-checked #3298

Closed
trocher opened this issue Feb 21, 2023 · 0 comments · Fixed by #3304
Closed

Annotation of implements is not properly type-checked #3298

trocher opened this issue Feb 21, 2023 · 0 comments · Fixed by #3304
Labels
bug - typechecker issue with typechecker

Comments

@trocher
Copy link
Contributor

trocher commented Feb 21, 2023

Version Information

  • vyper Version (output of vyper --version): 0.3.8+commit.7ff8f307
  • OS: OSX
  • Python Version (output of python --version): 3.8.0

What's your issue about?

At the moment, visit_ImplementsDecl relies on the fact that the object mapped to node.annotation.id in the namespace defines a method validate_implements to ensure that the given name corresponds to an interface.

def visit_ImplementsDecl(self, node):
interface_name = node.annotation.id
other_iface = self.namespace[interface_name]
other_iface.validate_implements(node)

It would probably be better to use type_from_annotation:

  def visit_ImplementsDecl(self, node):
      interface_name = node.annotation

      other_iface = type_from_annotation(interface_name)

      # Add a check to ensure that: isinstance(other_iface,InterfaceT)

      other_iface.validate_implements(node)

This would also have the advantage to give better error messages for the 2 following cases:

  • When a constant is given (currently the following is given AttributeError: 'Int' object has no attribute 'id'
  • When a type or more generally an identifier which is not an interface is given (currently for example: AttributeError: 'StructT' object has no attribute 'validate_implements')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - typechecker issue with typechecker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants