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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow equality checks between agent types #932

Merged
merged 3 commits into from Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -230,8 +230,14 @@ public static WurstType calculate(final ExprBinary term) {
// in jass code it is allowed to compare an integer with 'null'. wat?
return WurstTypeBool.instance();
}

if (leftType.isSubtypeOf(WurstNativeType.instance("agent", WurstTypeNull.instance()), term) && rightType.isSubtypeOf(WurstNativeType.instance("agent", WurstTypeNull.instance()), term)) {
// in jass code it is allowed to compare agents
return WurstTypeBool.instance();
}
}


// TODO check if the intersection of the basetypes of lefttpye and righttype is
// not empty. Example:
// class A implements B,C
Expand Down
Expand Up @@ -1384,4 +1384,15 @@ public void executeFuncWithStackTrace() {
);
}

@Test
public void agentTypeComparisonsWurst() {
testAssertErrorsLinesWithStdLib(true, "Cannot compare types sound with rect",
"package Test",
"function compare(sound s, rect r) returns boolean",
" return s == r",
"init",
" compare(null, null)"
);
}

}
Expand Up @@ -214,6 +214,26 @@ public void jassMultilineString() {
testJurstWithJass(true, false, jassCode, jurstCode);
}

@Test
public void jassAgentTypeComparison() {
String jassCode = Utils.string(
"function bar takes sound s, rect r returns boolean",
"return s == r",
"endfunction\n");


String jurstCode = Utils.string(
"package test",
" init",
" if bar(null, null)",
" testSuccess()",
" end",
" end",
"endpackage");

testJurstWithJass(true, true, jassCode, jurstCode);
}

@Test
public void testBigJassScript() throws IOException {
String jassCode = new String(Files.readAllBytes(Paths.get(Utils.getResourceFile("test.j"))));
Expand Down
Expand Up @@ -309,6 +309,10 @@ public void testAssertErrorsLines(boolean executeProg, String errorMessage, Stri
test().executeProg(executeProg).expectError(errorMessage).lines(input);
}

public void testAssertErrorsLinesWithStdLib(boolean executeProg, String errorMessage, String... input) {
test().withStdLib().executeProg(executeProg).expectError(errorMessage).lines(input);
}

protected void testAssertOk(String name, boolean executeProg, String prog) {
testAssertOkLines(executeProg, prog);
}
Expand Down