Skip to content

make type check errors use the to-string() method directly #1527

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

Open
wants to merge 2 commits into
base: horizon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/arr/compiler/compile-structs.arr
Original file line number Diff line number Diff line change
Expand Up @@ -1955,9 +1955,9 @@ data CompileError:
ED.text("Type checking failed because of a type inconsistency.")],
[ED.para:
ED.text("The type constraint "),
ED.highlight(ED.text(tostring(type-1)), [list: type-1.l], 0),
ED.highlight(ED.text(type-1.to-string()), [list: type-1.l], 0),
ED.text(" was incompatible with the type constraint "),
ED.highlight(ED.text(tostring(type-2)), [list: type-2.l], 1)]]
ED.highlight(ED.text(type-2.to-string()), [list: type-2.l], 1)]]
end,
method render-reason(self):
{type-1; type-2} = if self.type-1.l.before(self.type-2.l): {self.type-1; self.type-2} else: {self.type-2; self.type-1} end
Expand All @@ -1966,10 +1966,10 @@ data CompileError:
ED.text("Type checking failed because of a type inconsistency.")],
[ED.para:
ED.text("The type constraint "),
ED.code(ED.text(tostring(type-1))),
ED.code(ED.text(type-1.to-string())),
ED.text(" at "), draw-and-highlight(type-1.l),
ED.text(" was incompatible with the type constraint "),
ED.code(ED.text(tostring(type-2))),
ED.code(ED.text((type-2.to-string()))),
ED.text(" at "), draw-and-highlight(type-2.l)]]
end
| incorrect-type(bad-name :: String, bad-loc :: A.Loc, expected-name :: String, expected-loc :: A.Loc) with:
Expand Down Expand Up @@ -2019,15 +2019,15 @@ data CompileError:
[ED.error:
[ED.para:
ED.text("The type checker rejected your program because the type application "),
ED.highlight(ED.embed(self.app-type), [list: self.app-type.l], 0),
ED.highlight(ED.code(ED.text(self.app-type.to-string())), [list: self.app-type.l], 0),
ED.text(" expected " + tostring(self.expected-length) + " type arguments, "),
ED.text("but it received " + tostring(self.app-type.args.length()))]]
end,
method render-reason(self):
[ED.error:
[ED.para:
ED.text("The type checker rejected your program because the type application "),
ED.highlight(ED.embed(self.app-type), [list: self.app-type.l], 0),
ED.highlight(ED.code(ED.text(self.app-type.to-string())), [list: self.app-type.l], 0),
ED.text(" expected " + tostring(self.expected-length) + " type arguments, "),
ED.text("but it received " + tostring(self.app-type.args.length()))]]
end
Expand All @@ -2048,7 +2048,7 @@ data CompileError:
+ "given, but the type signature of the "),
ed-applicant],
[ED.para:
ED.embed(self.fun-typ)],
ED.code(ED.text(self.fun-typ.to-string()))],
[ED.para:
ED.text("indicates that it evaluates to a function accepting exactly "),
ED.ed-args(self.fun-typ.args.length()),
Expand All @@ -2069,7 +2069,7 @@ data CompileError:
ED.ed-args(self.app-expr.args.length()),
ED.text(" and the type signature of the applicant")],
[ED.para:
ED.embed(self.fun-typ)],
ED.code(ED.text(self.fun-typ.to-string()))],
[ED.para:
ED.text("indicates that it evaluates to a function accepting exactly "),
ED.ed-args(self.fun-typ.args.length()),
Expand Down
4 changes: 2 additions & 2 deletions src/arr/compiler/type-check-structs.arr
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ fun instantiate-object-type(typ :: Type, context :: Context) -> FoldResult<Type>
| t-existential(_, exists-l, _) =>
typing-error([list: C.unable-to-infer(exists-l)])
| else =>
fold-errors([list: C.incorrect-type(tostring(a-onto), a-onto.l, "a polymorphic type", a-l)])
fold-errors([list: C.incorrect-type(a-onto.to-string(), a-onto.l, "a polymorphic type", a-l)])
end
| t-record(_, _, _) =>
fold-result(typ, context)
Expand All @@ -1221,7 +1221,7 @@ fun instantiate-object-type(typ :: Type, context :: Context) -> FoldResult<Type>
instantiate-object-type(typ, context)
end)
| else =>
fold-errors([list: C.incorrect-type(tostring(typ), typ.l, "an object type", typ.l)])
fold-errors([list: C.incorrect-type(typ.to-string(), typ.l, "an object type", typ.l)])
end
end

Expand Down
22 changes: 11 additions & 11 deletions src/arr/compiler/type-check.arr
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ fun _checking(e :: Expr, expect-type :: Type, top-level :: Boolean, context :: C
| t-ref(arg-type, _, _) =>
checking(value, arg-type, top-level, context)
| else =>
typing-error([list: C.incorrect-type-expression(tostring(id-type), l, tostring(t-ref(id-type, l, false)), l, e)])
typing-error([list: C.incorrect-type-expression(id-type.to-string(), l, t-ref(id-type, l, false).to-string(), l, e)])
end
end)
| s-if-pipe(l, branches) =>
Expand Down Expand Up @@ -878,7 +878,7 @@ fun _synthesis(e :: Expr, top-level :: Boolean, context :: Context) -> TypingRes
| t-ref(arg-type, _, _) =>
typing-result(e, arg-type.set-loc(l), context)
| else =>
typing-error([list: C.incorrect-type-expression(tostring(id-type), id-type.l, tostring(t-ref(id-type, l, false)), l, e)])
typing-error([list: C.incorrect-type-expression(id-type.to-string(), id-type.l, t-ref(id-type, l, false).to-string(), l, e)])
end
end)
| s-id-letrec(l, id, safe) =>
Expand Down Expand Up @@ -911,7 +911,7 @@ fun _synthesis(e :: Expr, top-level :: Boolean, context :: Context) -> TypingRes
| t-ref(typ, _, _) =>
typing-result(new-get-bang, typ.set-loc(l), context)
| else =>
typing-error([list: C.incorrect-type-expression(tostring(field-type), field-type.l, "a ref type", l, e)])
typing-error([list: C.incorrect-type-expression(field-type.to-string(), field-type.l, "a ref type", l, e)])
end
end)
| s-bracket(l, obj, field) =>
Expand Down Expand Up @@ -1923,7 +1923,7 @@ fun synthesis-extend(update-loc :: Loc, obj :: Expr, obj-type :: Type, fields ::
| t-existential(_, l, _) =>
typing-error([list: C.unable-to-infer(l)])
| else =>
typing-error([list: C.incorrect-type-expression(tostring(obj-type), obj-type.l, "an object type", update-loc, obj)])
typing-error([list: C.incorrect-type-expression(obj-type.to-string(), obj-type.l, "an object type", update-loc, obj)])
end
end)
end)
Expand All @@ -1944,7 +1944,7 @@ fun synthesis-update(update-loc :: Loc, obj :: Expr, obj-type :: Type, fields ::
fold-result(link(A.s-data-field(field.l, field.name, new-value), fields), context)
end)
| else =>
fold-errors([list: C.incorrect-type(tostring(old-type), old-type.l, tostring(t-ref(old-type, update-loc, false)), update-loc)])
fold-errors([list: C.incorrect-type(old-type.to-string(), old-type.l, t-ref(old-type, update-loc, false).to-string(), update-loc)])
end
end
end, fields, context, empty).typing-bind(lam(final-fields, shadow context):
Expand All @@ -1965,14 +1965,14 @@ fun synthesis-update(update-loc :: Loc, obj :: Expr, obj-type :: Type, fields ::
fold-result(link(A.s-data-field(field.l, field.name, new-value), fields), context)
end)
| else =>
fold-errors([list: C.incorrect-type(tostring(old-type), old-type.l, tostring(t-ref(old-type, update-loc, false)), update-loc)])
fold-errors([list: C.incorrect-type(old-type.to-string(), old-type.l, t-ref(old-type, update-loc, false).to-string(), update-loc)])
end
end
end, fields, context, empty).typing-bind(lam(final-fields, shadow context):
typing-result(A.s-update(update-loc, obj, final-fields), obj-type, context)
end)
end)
# typing-error([list: C.incorrect-type-expression(tostring(obj-type), obj-type.l, "an object type", update-loc, obj)])
# typing-error([list: C.incorrect-type-expression(obj-type.to-string(), obj-type.l, "an object type", update-loc, obj)])
end
end)
end
Expand Down Expand Up @@ -2035,7 +2035,7 @@ fun check-fun(fun-loc :: Loc, body :: Expr, params :: List<A.Name>, args :: List
end)
end)
| else =>
typing-error([list: C.incorrect-type(tostring(expect-type), expect-type.l, "a function", fun-loc)])
typing-error([list: C.incorrect-type(expect-type.to-string(), expect-type.l, "a function", fun-loc)])
end.solve-bind()
end

Expand Down Expand Up @@ -2075,7 +2075,7 @@ fun synthesis-instantiation(l :: Loc, expr :: Expr, params :: List<A.Ann>, top-l
end)
| t-existential(_, exists-l, _) =>
typing-error([list: C.unable-to-infer(exists-l)])
| else => typing-error([list: C.incorrect-type(tostring(tmp-type), tmp-type.l, "a polymorphic type", l)])
| else => typing-error([list: C.incorrect-type(tmp-type.to-string(), tmp-type.l, "a polymorphic type", l)])
end
end)
end
Expand All @@ -2092,7 +2092,7 @@ fun handle-if-branch(branch :: A.IfBranch, context :: Context) -> FoldResult<{A.
end

fun synthesis-tuple-index(access-loc :: Loc, tup :: Expr, tup-type-loc :: Loc, tup-type :: Type, index :: Number, recreate :: (Loc, Expr, Number -> Expr), context :: Context) -> TypingResult:
non-tup-err = typing-error([list: C.incorrect-type(tostring(tup-type), tup-type-loc, "a tuple type", access-loc)])
non-tup-err = typing-error([list: C.incorrect-type(tup-type.to-string(), tup-type-loc, "a tuple type", access-loc)])
tuple-view(access-loc, tup-type-loc, tup-type,
lam(l, maybe-tup-members):
cases(Option<List<Type>>) maybe-tup-members:
Expand All @@ -2112,7 +2112,7 @@ end
fun tuple-view(access-loc :: Loc, tup-type-loc :: Loc, tup-type :: Type,
handle :: (Loc, Option<List<Type>> -> TypingResult),
context :: Context) -> TypingResult:
non-tup-err = typing-error([list: C.incorrect-type(tostring(tup-type), tup-type-loc, "a tuple type", access-loc)])
non-tup-err = typing-error([list: C.incorrect-type(tup-type.to-string(), tup-type-loc, "a tuple type", access-loc)])
cases(Type) tup-type:
| t-tuple(fields, _, _) =>
handle(tup-type-loc, some(fields))
Expand Down