Skip to content

Commit

Permalink
Typescript issues with propogating severity
Browse files Browse the repository at this point in the history
  • Loading branch information
robsimmons committed May 7, 2024
1 parent 81939af commit 221d850
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function loadJson(json: JsonData, facts: [Data, Data, Data][]): Data {
}
} else {
throw new DusaError([
{ type: 'Issue', msg: `Could not load ${typeof json} as JSON data triples` },
{
type: 'Issue',
msg: `Could not load ${typeof json} as JSON data triples`,
severity: 'error',
},
]);
}
return ref;
Expand Down Expand Up @@ -169,6 +173,7 @@ export class Dusa {
{
type: 'Issue',
msg: `Asserted predicates must start with a lowercase letter and include only alphanumeric characters, '${pred}' does not.`,
severity: 'error',
},
]);
}
Expand All @@ -181,6 +186,7 @@ export class Dusa {
msg: `Predicate ${pred} should have ${expected} argument${
expected === 1 ? '' : 's'
}, but the asserted fact has ${arity}`,
severity: 'error',
},
]);
}
Expand Down Expand Up @@ -241,6 +247,7 @@ export class Dusa {
{
type: 'Issue',
msg: "Cannot use 'solution' getter on programs with multiple solutions. Use sample() instead.",
severity: 'error',
},
]);
}
Expand Down
13 changes: 13 additions & 0 deletions src/language/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function checkPropositionArity(
expectedArity === 1 ? '' : 's'
}, but here it has ${arity}`,
loc: occurrence,
severity: 'error',
});
}
}
Expand Down Expand Up @@ -82,6 +83,7 @@ function checkFreeVarsInPremises(premises: ParsedPremise[]):
type: 'Issue',
msg: `Variable ${v} cannot be reused in a later premise because its first occurance was in an inequality`,
loc,
severity: 'error',
});
}
}
Expand All @@ -93,6 +95,7 @@ function checkFreeVarsInPremises(premises: ParsedPremise[]):
type: 'Issue',
msg: `Named wildcard ${dup} used multiple times in a rule.`,
loc,
severity: 'error',
});
}
}
Expand Down Expand Up @@ -129,6 +132,7 @@ function checkFreeVarsInPremises(premises: ParsedPremise[]):
type: 'Issue',
msg: `Only one side of an ${premise.type.toLowerCase()} can include a first occurance of a variable or a wildcard. The left side uses ${newA}, the right side uses ${newB}.`,
loc: premise.loc,
severity: 'error',
});
}
break;
Expand Down Expand Up @@ -183,6 +187,7 @@ export function checkFreeVarsInDecl(decl: ParsedDeclaration): Issue[] {
type: 'Issue',
msg: `Cannot include wildcard ${w} in the head of a rule.`,
loc: decl.conclusion.loc,
severity: 'error',
});
}

Expand All @@ -192,12 +197,14 @@ export function checkFreeVarsInDecl(decl: ParsedDeclaration): Issue[] {
type: 'Issue',
msg: `Variable '${v}' used in head of rule but was first defined in an inequality.`,
loc,
severity: 'error',
});
} else if (!fv.has(v)) {
errors.push({
type: 'Issue',
msg: `Variable '${v}' used in head of rule but not defined in a premise.`,
loc,
severity: 'error',
});
}
}
Expand All @@ -222,6 +229,7 @@ function checkFunctionalPredicatesInTerm(
msg: `The functional predicate '${pattern.name}' should be given ${expectedNum} argument${
expectedNum === 1 ? '' : 's'
}, but is given ${pattern.args.length} here`,
severity: 'error',
},
];
}
Expand All @@ -236,6 +244,7 @@ function checkFunctionalPredicatesInTerm(
type: 'Issue',
loc: pattern.loc,
msg: `Built-in ${pattern.name} (${pattern.symbol}) expects no argument, has ${pattern.args.length}`,
severity: 'error',
},
];
}
Expand All @@ -247,6 +256,7 @@ function checkFunctionalPredicatesInTerm(
type: 'Issue',
loc: pattern.loc,
msg: `Built-in ${pattern.name} (${pattern.symbol}) expects two arguments, has ${pattern.args.length}`,
severity: 'error',
},
];
}
Expand All @@ -259,6 +269,7 @@ function checkFunctionalPredicatesInTerm(
type: 'Issue',
loc: pattern.loc,
msg: `Built-in ${pattern.name} (${pattern.symbol}) needs to have one of its arguments grounded by previous premises, and that is not the case here.`,
severity: 'error',
},
];
}
Expand All @@ -277,6 +288,7 @@ function checkFunctionalPredicatesInTerm(
}) needs to have all of its arguments grounded by previous premises, but the argument '${termToString(
arg,
)}' is not ground`,
severity: 'error',
},
];
}
Expand All @@ -303,6 +315,7 @@ function checkFunctionalPredicatesInTerm(
}) needs to have all but one of its arguments grounded by previous premises, but the arguments '${termToString(
nonGround,
)}' and '${termToString(arg)}' are both not ground.`,
severity: 'error',
},
];
}
Expand Down

0 comments on commit 221d850

Please sign in to comment.