From a709a53f35583b89329a0ce1e40c5bdd76ddf82b Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 8 Feb 2024 14:07:57 +0100 Subject: [PATCH] test for INCOMPATIBLE_RETURN_TYPE --- .../tests/validation/JvmGenericTypeValidatorTest.java | 8 ++++++++ .../testdata/test/SuperTypeClass.java | 3 +++ 2 files changed, 11 insertions(+) diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/validation/JvmGenericTypeValidatorTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/validation/JvmGenericTypeValidatorTest.java index 86263bf065f..0e6c7ccae28 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/validation/JvmGenericTypeValidatorTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/validation/JvmGenericTypeValidatorTest.java @@ -460,6 +460,14 @@ public void testWildcardSuperType() throws Exception { validationHelper.assertNoErrors(model); } + @Test public void testOverrideIncompatbileReturnType() throws Exception { + var source = "class Foo extends test.SuperTypeClass { def Integer stringMethod() {null} }"; + var model = parse(source); + validationHelper.assertError(model, MY_METHOD, INCOMPATIBLE_RETURN_TYPE, + source.indexOf("Integer"), "Integer".length(), + "incompatible", "stringMethod"); + } + @Test public void testOverrideHides() throws Exception { var source = "class Foo extends test.SuperTypeClass { def private void foo() {} }"; var model = parse(source); diff --git a/org.eclipse.xtext.xbase.tests/testdata/test/SuperTypeClass.java b/org.eclipse.xtext.xbase.tests/testdata/test/SuperTypeClass.java index 45c54ee10dc..dd79151114b 100644 --- a/org.eclipse.xtext.xbase.tests/testdata/test/SuperTypeClass.java +++ b/org.eclipse.xtext.xbase.tests/testdata/test/SuperTypeClass.java @@ -16,4 +16,7 @@ public abstract class SuperTypeClass { public void foo() { } + public String stringMethod() { + return null; + } }