Skip to content

Commit

Permalink
#6 Number subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mraak committed Feb 22, 2019
1 parent 04a065f commit 9ad6507
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ function handleAssignmentExpressionType(scope,exprNode,targetNode,sourceNode,isA
}
// target already has an implied type?
if (targetType) {
if (!typesMatch(sourceType,targetType)) {
if (!isAssignmentAllowed(targetType,sourceType)) {
if (targetType.inferred == "undef") {
delete targetType.inferred;
Object.assign(targetType,sourceType);
Expand Down Expand Up @@ -1673,6 +1673,23 @@ function typesMatch(type1,type2) {
);
}

function isAssignmentAllowed(type1, type2){
if(typesMatch(type1, type2)){
return true;
}

let matches = {
int: ["int"],
number: ["number", "int", "finite"],
finite: ["finite", "int"],
bint: ["bint", "int"]
}
let type1ID = getTypeID(type1)
let type2ID = getTypeID(type2)

return matches[type1ID] && matches[type1ID].includes(type2ID)
}

function isNumberOrSubtype(type) {
var typeID = getTypeID(type);
return (typeID == "number" || isFiniteOrSubtype(typeID));
Expand Down

0 comments on commit 9ad6507

Please sign in to comment.