JS backend: fix "is Boolean" check.
This commit is contained in:
@@ -51,4 +51,8 @@ public class RTTITest extends SingleFileTranslationTest {
|
|||||||
public void testStdlibEmptyListClass() throws Exception {
|
public void testStdlibEmptyListClass() throws Exception {
|
||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testIsJsPrimitiveType() throws Exception {
|
||||||
|
checkFooBoxIsOk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ public final class PatternTranslator extends AbstractTranslator {
|
|||||||
if (NamePredicate.STRING.apply(typeName)) {
|
if (NamePredicate.STRING.apply(typeName)) {
|
||||||
jsSTypeName = "string";
|
jsSTypeName = "string";
|
||||||
}
|
}
|
||||||
|
else if (NamePredicate.BOOLEAN.apply(typeName)) {
|
||||||
|
jsSTypeName = "boolean";
|
||||||
|
}
|
||||||
else if (NamePredicate.LONG.apply(typeName)) {
|
else if (NamePredicate.LONG.apply(typeName)) {
|
||||||
return JsAstUtils.isLong(expressionToMatch);
|
return JsAstUtils.isLong(expressionToMatch);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -59,6 +59,9 @@ public final class NamePredicate implements Predicate<Name> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static final NamePredicate NUMBER = new NamePredicate("Number");
|
public static final NamePredicate NUMBER = new NamePredicate("Number");
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static final NamePredicate BOOLEAN = new NamePredicate("Boolean");
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final NamePredicate CHAR = new NamePredicate(PrimitiveType.CHAR.getTypeName());
|
public static final NamePredicate CHAR = new NamePredicate(PrimitiveType.CHAR.getTypeName());
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
enum class Type {
|
||||||
|
NUMBER
|
||||||
|
STRING
|
||||||
|
BOOLEAN
|
||||||
|
OBJECT
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: Any, actualType: Type) {
|
||||||
|
assertEquals(actualType == Type.NUMBER, a is Int, "$a is Int")
|
||||||
|
assertEquals(actualType == Type.NUMBER, a is Number, "$a is Number")
|
||||||
|
assertEquals(actualType == Type.NUMBER, a is Double, "$a is Double")
|
||||||
|
assertEquals(actualType == Type.BOOLEAN, a is Boolean, "$a is Boolean")
|
||||||
|
assertEquals(actualType == Type.STRING, a is String, "$a is String")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
test(1, Type.NUMBER)
|
||||||
|
|
||||||
|
test(12.3, Type.NUMBER)
|
||||||
|
test(12.3f, Type.NUMBER)
|
||||||
|
|
||||||
|
test("text", Type.STRING)
|
||||||
|
|
||||||
|
test(true, Type.BOOLEAN)
|
||||||
|
test(false, Type.BOOLEAN)
|
||||||
|
|
||||||
|
test(object {}, Type.OBJECT)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user