Fix type annotations. Close #176
This commit is contained in:
@@ -63,7 +63,7 @@ class Helpers {
|
||||
|
||||
public static function parseComplexType(path:String, ?from:ReaderExp):ComplexType {
|
||||
// Trick Haxe into parsing it for us:
|
||||
var typeCheckStr = '(thing : $path)';
|
||||
var typeCheckStr = 'var thing:$path;';
|
||||
var errorMessage = 'Haxe could not parse a complex type from `$path` in `${typeCheckStr}`';
|
||||
|
||||
function throwError() {
|
||||
@@ -76,7 +76,9 @@ class Helpers {
|
||||
try {
|
||||
var typeCheckExpr = Context.parse(typeCheckStr, Context.currentPos());
|
||||
return switch (typeCheckExpr.expr) {
|
||||
case EParenthesis({pos: _, expr: ECheckType(_, complexType)}):
|
||||
case EVars([{
|
||||
type: complexType
|
||||
}]):
|
||||
complexType;
|
||||
default:
|
||||
throwError();
|
||||
|
@@ -90,7 +90,7 @@ class Reader {
|
||||
RawHaxeBlock(stream.expect("closing }#", () -> stream.takeUntilAndDrop("}#")));
|
||||
};
|
||||
|
||||
readTable[":"] = (stream:Stream, k) -> TypedExp(nextToken(stream, "a type path"), assertRead(stream, k));
|
||||
readTable[":"] = (stream:Stream, k) -> TypedExp(stream.expect("a type path", () -> stream.takeUntilAndDrop(" ")), assertRead(stream, k));
|
||||
|
||||
readTable["&"] = (stream:Stream, k) -> MetaExp(nextToken(stream, "a meta symbol like mut, optional, rest"), assertRead(stream, k));
|
||||
|
||||
|
@@ -431,6 +431,10 @@ class BasicTestCase extends Test {
|
||||
}
|
||||
#end
|
||||
|
||||
function testLambdaTypeAnnotations() {
|
||||
_testLambdaTypeAnnotations();
|
||||
}
|
||||
|
||||
var aNullToPrint = null;
|
||||
}
|
||||
|
||||
|
@@ -736,6 +736,12 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
|
||||
(function set_staticProp [v] (set _staticProp v))
|
||||
(function get_staticProp [] _staticProp)
|
||||
|
||||
(var :(Int,Int)->Bool lambdaTest ->[a b] true)
|
||||
(var :()->Void lambdaTest2 ->[] (return))
|
||||
(function _testLambdaTypeAnnotations []
|
||||
(Assert.isTrue (lambdaTest 5 6))
|
||||
(lambdaTest2))
|
||||
|
||||
(function _testHaxeProperties []
|
||||
(Assert.equals 5 staticProp)
|
||||
(Assert.equals 9 (set staticProp 9))
|
||||
|
Reference in New Issue
Block a user