Skip to content

Commit

Permalink
also verify error position for INCOMPATIBLE_RETURN_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Jan 15, 2024
1 parent 1a927f8 commit eee1bb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AccessorsCompilerTest extends AbstractXtendCompilerTest {

@Test
def void testCannotOverrideWithConflictingReturnType() {
file('''
val source = '''
import org.eclipse.xtend.lib.annotations.Accessors
class Foo {
def String getFoo() {"foo"}
Expand All @@ -89,7 +89,10 @@ class AccessorsCompilerTest extends AbstractXtendCompilerTest {
class Bar extends Foo {
@Accessors int foo
}
''').assertError(XtendPackage.Literals.XTEND_FIELD, INCOMPATIBLE_RETURN_TYPE, "incompatible", "getFoo")
'''
file(source).assertError(XtendPackage.Literals.XTEND_FIELD, INCOMPATIBLE_RETURN_TYPE,
source.indexOf("@Accessors int foo"), "@Accessors int foo".length,
"incompatible", "getFoo")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,11 @@ public void testClassMustBeAbstract_06() throws Exception {
}

@Test public void testInterfaceIncompatibleReturnType_0() throws Exception {
XtendInterface xtendInterface = interfaze("interface Foo extends test.SuperInterface { override Boolean string() }");
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE);
var source = "interface Foo extends test.SuperInterface { override Boolean string() }";
XtendInterface xtendInterface = interfaze(source);
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE,
source.indexOf("Boolean"), "Boolean".length(),
"return type is incompatible with", "string()");
}

@Test public void testInterfaceIncompatibleReturnType_1() throws Exception {
Expand All @@ -815,8 +818,11 @@ public void testClassMustBeAbstract_06() throws Exception {
}

@Test public void testInterfaceIncompatibleReturnType_2() throws Exception {
XtendInterface xtendInterface = interfaze("interface Foo extends test.SomeInterface { override void foo() }");
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE);
var source = "interface Foo extends test.SomeInterface { override void foo() }";
XtendInterface xtendInterface = interfaze(source);
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE,
source.indexOf("void"), "void".length(),
"return type is incompatible with", "foo()");
}

@Test public void testInterfaceIncompatibleGenericReturnType_0() throws Exception {
Expand All @@ -825,8 +831,10 @@ public void testClassMustBeAbstract_06() throws Exception {
}

@Test public void testInterfaceIncompatibleGenericReturnType_1() throws Exception {
XtendInterface xtendInterface = interfaze("interface Foo extends test.SuperInterface { override java.util.List<Object> returnsListString() }");
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE);
var source = "interface Foo extends test.SuperInterface { override java.util.List<Object> returnsListString() }";
XtendInterface xtendInterface = interfaze(source);
helper.assertError(xtendInterface.getMembers().get(0), XTEND_FUNCTION, INCOMPATIBLE_RETURN_TYPE,
source.indexOf("java.util.List<Object>"), "java.util.List<Object>".length());
}

@Test public void testInterfaceIncompatibleGenericReturnType_2() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ public void testCannotOverrideWithConflictingReturnType() {
_builder.newLine();
_builder.append("}");
_builder.newLine();
this._validationTestHelper.assertError(this.file(_builder.toString()), XtendPackage.Literals.XTEND_FIELD, IssueCodes.INCOMPATIBLE_RETURN_TYPE, "incompatible", "getFoo");
final String source = _builder.toString();
this._validationTestHelper.assertError(this.file(source), XtendPackage.Literals.XTEND_FIELD, IssueCodes.INCOMPATIBLE_RETURN_TYPE,
source.indexOf("@Accessors int foo"), "@Accessors int foo".length(),
"incompatible", "getFoo");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
Expand Down

0 comments on commit eee1bb0

Please sign in to comment.