Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix new resolution of unary minus #4737

Merged
merged 9 commits into from
Jan 3, 2024
Prev Previous commit
Next Next commit
fix: Unary - to resolve to base type (like “int”, not “nat”)
  • Loading branch information
RustanLeino committed Nov 2, 2023
commit 2038950244ac29f4e0469db77257e065e606db27
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public partial class PreTypeResolver {
} else if (expr is NegationExpression) {
var e = (NegationExpression)expr;
ResolveExpression(e.E, resolutionContext);
e.PreType = e.E.PreType;
e.PreType = CreatePreTypeProxy("result of unary -");
AddSubtypeConstraint(e.PreType, e.E.PreType, e.E.tok,
$"type of argument to unary - ({{1}}) must agree with the result type ({{0}})");
AddConfirmation(PreTypeConstraints.CommonConfirmationBag.NumericOrBitvector, e.E.PreType, e.E.tok, "type of unary - must be of a numeric or bitvector type (instead got {0})");
// Note, e.ResolvedExpression will be filled in during CheckTypeInference, at which time e.PreType has been determined

Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Resolver/PreType/PreTypeToType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PreTypeToTypeVisitor : ASTVisitor<IASTVisitorContext> {
}

// Case: fixed pre-type type
if (expr is LiteralExpr or ThisExpr or UnaryExpr or BinaryExpr) {
if (expr is LiteralExpr or ThisExpr or UnaryExpr or BinaryExpr or NegationExpression) {
// Note, for the LiteralExpr "null", we expect to get a possibly-null type, whereas for a reference-type ThisExpr, we expect
// to get the non-null type. The .PreType of these two distinguish between those cases, because the latter has a .PrintablePreType
// field that gives the non-null type.
Expand Down