Skip to content
Snippets Groups Projects
Commit a07f6098 authored by pycsham's avatar pycsham
Browse files

fixed some funtion return bugs left over from A3. Passing 58/61 locally

parent cd7407ce
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,7 @@ class MethodNode(ASTNode):
self.children = []
self.typeName = typeName
self.order = order
self.myType = None
# get method name
nameNodes = getParseTreeNodes(['ID'], parseTree, ['params', 'type', 'methodBody'])
......@@ -160,12 +161,12 @@ class MethodNode(ASTNode):
for n in returnNodes:
# Checking for functions of type void
# Only valid if either the function doesn't have a return statement(checked above), or the return statement is a semicolon (return;)
if self.myType.name == "void":
if self.myType and self.myType.name == "void":
if n.myType:
raise Exception("ERROR: return type of function {} doesn't match with return statement.".format(self.name))
return
# Checking for non void cases
if not self.myType.assignable(n.myType):
if self.myType and not self.myType.assignable(n.myType):
raise Exception("ERROR: return type of function {} doesn't match with return statement.".format(self.name))
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment