Skip to content

Commit

Permalink
Disallow __init__ in interfaces: fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyh committed Jan 29, 2013
1 parent 30e13f4 commit 3dbea40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,22 @@ def infer_local_variable_type(self, x, y, z):

Type visit_type_def(self, TypeDef defn):
"""Type check a type definition (class or interface)."""
typ = self.lookup(defn.name, GDEF).node
typ = (TypeInfo)self.lookup(defn.name, GDEF).node
self.errors.set_type(defn.name, defn.is_interface)
self.check_unique_interface_implementations((TypeInfo)typ)
self.check_interface_errors((TypeInfo)typ)
self.check_unique_interface_implementations(typ)
self.check_interface_errors(typ)
self.check_no_constructor_if_interface(typ)
self.accept(defn.defs)
self.report_error_if_statements_in_class_body(defn.defs)
self.errors.set_type(None, False)
void check_no_constructor_if_interface(self, TypeInfo typ):
if not typ.is_interface:
return
ctor = typ.get_method('__init__')
if ctor is None:
return
self.msg.interface_has_constructor(ctor)
void check_unique_interface_implementations(self, TypeInfo typ):
"""Check that each interface is implemented only once."""
Expand Down
3 changes: 3 additions & 0 deletions messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ class MessageBuilder:
else:
return False

void interface_has_constructor(self, Context context):
self.fail('An interface must not define a constructor', context)


str capitalize(str s):
"""Capitalize the first character of a string."""
Expand Down

0 comments on commit 3dbea40

Please sign in to comment.