Closed blerner closed 6 months ago
(@jpolitz , @shriram , would like your input here if you have time)
@jpolitz here's a thought to fix question 2 above:
PRecordAnn
in runtime.js with an optional name
field (and ditto PTupleAnn
)PRecordAnn.prototype.check
, if there is a name field then use it, else use "record" (or "Object", whatever we decide)compile-ann
to take in a Option<String>
name, that we can supply in a-type-let
definitions (possibly some other analogous locations) and leave out in other situations.The idea being, we'd wind up compiling type Point2D = {px:: Number, py:: Number}
as
var Point2D## = R.mRA([ "px", "py" ],
[ L[7], L[8] ],
{ "px": $type$Number1, "py": $type$Number1 },
"Point2D"
);
so that when it's used in an annotation-checking position, the runtime can say "oh, I'm a named annotation, I can give a better error message here".
I think this approach will work across modules and not require AST access (i.e. it'll work at the command line). The only downside I can think of is that if a type is aliased when imported or exported, the error message will be in terms of the original defining name.
I've just pushed an implementation of this idea to the PR above, so we can try it out.
Consider a simple program:
Then consider two bad uses of that function, and the errors we get on the command line or in CPO:
next-pos(3)
next-pos({ x: 3, y: 5})
Missing field
px
is required at file:///home/blerner/pyret-lang/temp.arr:10:17-10:29Missing field
py
is required at file:///home/blerner/pyret-lang/temp.arr:10:31-10:43 Pyret stack: file:///home/blerner/pyret-lang/temp.arr: line 16, column 0Questions:
render-fancy-reason
available there. But is it worth trying to special-case this error message and see if we can't get it to show "The Point2D annotation was not satisfied..."? (I can get this to work when Point2D is defined in the same file as it's being used, but I can't seem to get my localhost instance to read a shared gdrive file, so I can't test yet whether it works across files...which is where it's most useful.)