Skip to content

unsound typechecking for + binary operator #33

@bennn

Description

@bennn

If a variable X refers to a function in "module scope" and an integer in "function body scope", then the expression 1 + X will report a type error saying X has function type.

The expression X + 1 works fine.

Same things happen with the * binary operator.

Here's an example. The variable z is bound to a function in "module scope" and to an integer within the body of the function f. On the line marked ERROR, the typechecker (unsoundly) believes that z has type Function([], Int)

def z ()->int:
  return 0

def f()->int:
  z = 4
  y = z + 1 # OK
  x = 1 + z # ERROR
  return 0

Error message:

====STATIC TYPE ERROR=====
bar.py:7:6: Int and Function([], Int) are invalid operand types for the binary operator +. (code BINOP_INCOMPAT)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions