Merge pull request 'Undefined variables and column aggregations' (#43) from fix/undefined-variable into main
Reviewed-on: #43
This commit is contained in:
@@ -13,7 +13,6 @@ from midas.checker.types import (
|
|||||||
Function,
|
Function,
|
||||||
ParamSpec,
|
ParamSpec,
|
||||||
Type,
|
Type,
|
||||||
UnknownType,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -97,11 +96,9 @@ class ColumnGroupByMethodRegistry(MethodRegistry[Call]):
|
|||||||
positional=[],
|
positional=[],
|
||||||
keywords={},
|
keywords={},
|
||||||
)
|
)
|
||||||
if not isinstance(returns, ColumnType):
|
|
||||||
returns = ColumnType(type=UnknownType())
|
|
||||||
signature = Function(
|
signature = Function(
|
||||||
params=ParamSpec(mixed=real_params),
|
params=ParamSpec(mixed=real_params),
|
||||||
returns=returns,
|
returns=ColumnType(type=returns),
|
||||||
)
|
)
|
||||||
|
|
||||||
result: CallResult = self.dispatcher.get_result(
|
result: CallResult = self.dispatcher.get_result(
|
||||||
|
|||||||
@@ -364,14 +364,12 @@ class ColumnMethodRegistry(MethodRegistry[Call]):
|
|||||||
Type: the result type
|
Type: the result type
|
||||||
"""
|
"""
|
||||||
|
|
||||||
returns: Type = ColumnType(type=TopType())
|
returns: Type = TopType()
|
||||||
if formula:
|
if formula:
|
||||||
returns = ColumnType(
|
returns = self._resolve_formula_type(
|
||||||
type=self._resolve_formula_type(
|
|
||||||
call,
|
call,
|
||||||
formula(call.column.type),
|
formula(call.column.type),
|
||||||
)
|
)
|
||||||
)
|
|
||||||
signature = Function(
|
signature = Function(
|
||||||
params=ParamSpec(
|
params=ParamSpec(
|
||||||
kw=[
|
kw=[
|
||||||
|
|||||||
@@ -97,6 +97,21 @@ class Resolver(p.Stmt.Visitor[None], p.Expr.Visitor[None]):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_defined(self, name: str) -> bool:
|
||||||
|
"""Check whether the given variable is defined
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): the name of the variable
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: `True` if the variable is defined in the closest scope where it
|
||||||
|
is declared, `False` otherwise
|
||||||
|
"""
|
||||||
|
for scope in reversed(self.scopes):
|
||||||
|
if name in scope:
|
||||||
|
return scope[name]
|
||||||
|
return False
|
||||||
|
|
||||||
def resolve_function(self, function: p.Function) -> None:
|
def resolve_function(self, function: p.Function) -> None:
|
||||||
"""Resolve a function definition
|
"""Resolve a function definition
|
||||||
|
|
||||||
@@ -230,7 +245,7 @@ class Resolver(p.Stmt.Visitor[None], p.Expr.Visitor[None]):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def visit_variable_expr(self, expr: p.VariableExpr) -> None:
|
def visit_variable_expr(self, expr: p.VariableExpr) -> None:
|
||||||
if len(self.scopes) != 0 and self.scopes[-1].get(expr.name) is False:
|
if self.is_declared(expr.name) and not self.is_defined(expr.name):
|
||||||
self.reporter.error(
|
self.reporter.error(
|
||||||
expr.location,
|
expr.location,
|
||||||
f"Variable '{expr.name}' is declared but may not be defined",
|
f"Variable '{expr.name}' is declared but may not be defined",
|
||||||
|
|||||||
@@ -4305,9 +4305,7 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {}
|
"type": {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4342,9 +4340,7 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {}
|
"type": {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4379,11 +4375,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4418,11 +4412,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "float"
|
"name": "float"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4457,11 +4449,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4496,11 +4486,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4535,11 +4523,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4574,11 +4560,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4613,11 +4597,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4652,9 +4634,7 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {}
|
"type": {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4689,11 +4669,9 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"name": "int"
|
"name": "int"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
@@ -4728,9 +4706,7 @@
|
|||||||
"arguments": [],
|
"arguments": [],
|
||||||
"keywords": {}
|
"keywords": {}
|
||||||
},
|
},
|
||||||
"type": {
|
|
||||||
"type": {}
|
"type": {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
|
|||||||
Reference in New Issue
Block a user