Change Binder variable type if value is assigned to null variable, or null is assigned to a variable type
This commit is contained in:
parent
3efa6a6359
commit
82e13a85e2
|
@ -159,12 +159,20 @@ namespace Upsilon.Binder
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (boundExpression.Type != variable.Type)
|
// don't allow assigning different typed variables to a variable, unless either of them is nil, allow assigning nil to all variables
|
||||||
|
if (boundExpression.Type != variable.Type && (variable.Type != Type.Nil || boundExpression.Type == Type.Nil))
|
||||||
|
{
|
||||||
|
if (variable.Type == Type.Nil || boundExpression.Type == Type.Nil)
|
||||||
|
{
|
||||||
|
variable.Type = boundExpression.Type;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_diagnostics.LogCannotConvert(boundExpression.Type, variable.Type, e.Span);
|
_diagnostics.LogCannotConvert(boundExpression.Type, variable.Type, e.Span);
|
||||||
return new BoundExpressionStatement(boundExpression);
|
return new BoundExpressionStatement(boundExpression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new BoundVariableAssignment(variable, boundExpression);
|
return new BoundVariableAssignment(variable, boundExpression);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Upsilon.Binder
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type Type { get; }
|
public Type Type { get; set; }
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue