Skip to content

Commit

Permalink
Fix for #863: respect declared type of variable for STC
Browse files Browse the repository at this point in the history
GROOVY-9058, GROOVY-9064
  • Loading branch information
eric-milles committed Apr 3, 2019
1 parent 71a5821 commit e29dba0
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -609,6 +610,35 @@ public void testCompileStatic_1506() throws Exception {
// expectingCompiledClasses("Client");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/863
public void testCompileStatic_9058() throws Exception {
assumeTrue(isAtLeastGroovy(25));

IPath[] paths = createSimpleProject("Project", true);

env.addClass(paths[1], "p", "Foo",
"package p;\n" +
"public class Foo {\n" +
" @SuppressWarnings(\"rawtypes\")\n" +
" public java.util.List bar() { return null; }\n" +
"}\n");

env.addGroovyClass(paths[1], "p", "Main",
"package p\n" +
"class Main {\n" +
" @groovy.transform.CompileStatic\n" +
" void meth() {\n" +
" List<Object[]> rows = new Foo().bar()\n" +
" rows.each { row ->\n" + // should be Object[]
" def col = row[0]\n" +
" }\n" +
" }\n" +
"}\n");

fullBuild(paths[0]);
expectingNoProblems();
}

@Test
public void testCompileStatic_ArrayArray() throws Exception {
JDTResolver.recordInstances = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -47,14 +47,14 @@ public void testDefaultAndStaticMethodInInterface() {
}

@Test
public void testFunctionalInterfaceInterfaceCoercion() {
public void testFunctionalInterfaceCoercion() {
runConformTest(new String[] {
"Foo.groovy",
"@groovy.transform.CompileStatic\n" +
"class Foo {\n" +
" String bar\n" +
" def baz() {\n" +
" Collection<Foo> coll\n" +
" Collection<Foo> coll = []\n" +
" coll.removeIf { it.bar == null }\n" + // Closure should coerce to SAM type java.util.function.Predicate
" }\n" +
"}\n",
Expand Down
Loading

0 comments on commit e29dba0

Please sign in to comment.