Skip to content

Commit

Permalink
GROOVY-11364: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 30, 2024
1 parent b87d2dc commit 69fca65
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
user.gradle
build.bat
.gradle/
target/
build/
bin/
out/

*.DS_Store
Expand All @@ -14,10 +16,13 @@ out/
*.iml
*.ipr
*.iws
.shelf

.settings/
.classpath
.project
bin/

.fleet
.shelf
.vscode
.jqwik-database
verification-metadata.dryrun.xml
66 changes: 63 additions & 3 deletions src/test/groovy/transform/stc/MethodReferenceTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import static groovy.test.GroovyAssert.shouldFail
final class MethodReferenceTest {

private static final imports = '''\
import groovy.transform.*
import java.util.function.*
import java.util.stream.Collectors
import groovy.transform.CompileStatic
'''

@Test // class::instanceMethod
Expand Down Expand Up @@ -104,7 +104,7 @@ final class MethodReferenceTest {
class Two extends One { }
@CompileStatic @groovy.transform.Immutable(knownImmutableClasses=[Function])
@CompileStatic @Immutable(knownImmutableClasses=[Function])
class FunctionHolder<T> {
Function<T, ?> extractor
Expand Down Expand Up @@ -622,6 +622,29 @@ final class MethodReferenceTest {
'''
}

@Test // instance::instanceMethod -- GROOVY-11364
void testFunctionII5() {
assertScript imports + '''
abstract class A<N extends Number> {
protected N process(N n) { n }
}
@CompileStatic
class C extends A<Integer> {
static void consume(Optional<Integer> option) {
def result = option.orElse(null)
assert result instanceof Integer
assert result == 42
}
void test() {
consume(Optional.of(42).map(this::process))
}
}
new C().test()
'''
}

@NotYetImplemented
@Test // instance::instanceMethod -- GROOVY-10057
void testPredicateII() {
Expand Down Expand Up @@ -681,7 +704,7 @@ final class MethodReferenceTest {
@Test // instance::instanceMethod -- GROOVY-11026
void testBiFunctionII() {
assertScript imports + '''
@groovy.transform.CompileDynamic
@CompileDynamic
def <In,InOut> InOut m(BiFunction<In,InOut,InOut> beef) {
beef.apply(0,'boo')
}
Expand Down Expand Up @@ -1378,6 +1401,43 @@ final class MethodReferenceTest {
assert err.message.contains("Failed to find class method 'toString()' for the type: java.lang.Object")
}

@Test // GROOVY-10859
void testDynamicMethodSelection() {
for (tag in ['@TypeChecked', '@CompileStatic', '@CompileDynamic']) {
assertScript imports + """
$tag
void test() {
def result = [[]].stream().flatMap(List::stream).toList()
assert result.isEmpty()
}
test()
"""
}
}

@NotYetImplemented
@Test // GROOVY-10904
void testPropertyMethodLocation() {
for (tag in ['@TypeChecked', '@CompileStatic', '@CompileDynamic']) {
assertScript imports + """
$tag
class Test {
static class Profile {
String foo, bar
}
Map<String, Profile> profiles = [new Profile()].stream()
.collect(Collectors.toMap(Profile::getFoo, Function.identity()))
static main(args) {
assert this.newInstance().getProfiles().size() == 1
}
}
"""
}
}

@Test // GROOVY-10742
void testIncompatibleReturnType() {
def err = shouldFail imports + '''
Expand Down

0 comments on commit 69fca65

Please sign in to comment.