Skip to content

void return type in L_fun unable to be type checked #207

@mpahrens

Description

@mpahrens

When making an example program following the L_fun grammar, I expect the following program to be able to parse and type check:

def foo() -> void :
   print(1)

the type annotation, void, gets parsed as Name('void') similar to int and bool.

In type_check_Lfun.py, there is no case for Name('void') and so type checking the program causes an error instead:

def parse_type_annot(self, annot):
      match annot:
        case Name(id):
          if id == 'int':
            return IntType()
          elif id == 'bool':
            return BoolType()
          else:
            raise Exception('parse_type_annot: unexpected ' + repr(annot))

Exception: parse_type_annot: unexpected Name('void')

Omitting the -> void return type annotation causes the python.ast parser to put a None as the return type annotation rather than VoidType() like we might expect.

Adding a case for id == 'void' seems to work, but before I make a pull request, I wanted to see if I am missing anything by doing so.
Since VoidType() has an explicit case in parse_type_annot(...), I could imagine that there is another way for the parser to produce a VoidType() annotation itself without me adding this case.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions