-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[incubator-kie-issues-1752] TCK failure-Lambda function returns null #6261
base: main
Are you sure you want to change the base?
Changes from 3 commits
404c291
f5731cd
367f0e1
8bc77b2
56620c8
5d4b68f
c0123fb
5cb934c
61699e3
17a8abb
6f56cfc
b2b0b03
fe19990
93e22ab
bc6e374
0560f1f
7013c13
55d173b
62ce7a1
365eb15
4995fbd
a69fbe7
0cc7c2c
5c44070
19fc323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,11 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.lang.types; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.kie.dmn.feel.lang.SimpleType; | ||
|
@@ -40,18 +40,15 @@ public GenFnType(List<Type> argsGen, Type returnGen) { | |
|
||
@Override | ||
public boolean isInstanceOf(Object o) { | ||
if (o instanceof FEELFunction) { | ||
FEELFunction oFn = (FEELFunction) o; | ||
List<List<Param>> signatures = oFn.getParameters().stream().filter(signature -> signature.size() == argsGen.size()).collect(Collectors.toList()); | ||
for (List<Param> signature : signatures) { | ||
if (signature.size() == argsGen.size() && IntStream.range(0, argsGen.size()).allMatch(i -> argsGen.get(i).conformsTo(signature.get(i).type))) { | ||
return true; | ||
} | ||
if (o instanceof FEELFunction oFn) { | ||
List<List<Param>> parameters = oFn.getParameters(); | ||
if(parameters.isEmpty()){ | ||
//this is used to consider function as parameter | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HI @bncriju |
||
} | ||
return false; | ||
} else { | ||
return false; | ||
return checkSignatures(parameters,argsGen); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
|
@@ -69,13 +66,22 @@ public String getName() { | |
|
||
@Override | ||
public boolean conformsTo(Type t) { | ||
if (t instanceof GenFnType) { | ||
GenFnType fnT = (GenFnType) t; | ||
if (t instanceof GenFnType fnT) { | ||
return fnT.argsGen.size() == this.argsGen.size() && | ||
IntStream.range(0, argsGen.size()).allMatch(i -> fnT.argsGen.get(i).conformsTo(this.argsGen.get(i))) && | ||
this.returnGen.conformsTo(fnT.returnGen); | ||
IntStream.range(0, argsGen.size()).allMatch(i -> fnT.argsGen.get(i).conformsTo(this.argsGen.get(i))) && | ||
this.returnGen.conformsTo(fnT.returnGen); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bncriju Please remove those 2 whitespaces |
||
return t == BuiltInType.FUNCTION; | ||
} | ||
} | ||
} | ||
|
||
static boolean checkSignatures(List<List<Param>> parameters, List<Type> argsGen){ | ||
List<List<Param>> signatures = parameters.stream().filter(signature -> signature.size() == argsGen.size()).toList(); | ||
for (List<Param> signature : signatures) { | ||
if (signature.size() == argsGen.size() && IntStream.range(0, argsGen.size()).allMatch(i -> argsGen.get(i).conformsTo(signature.get(i).type))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package org.kie.dmn.feel.lang.types; | ||
yesamer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.kie.dmn.feel.lang.Type; | ||
import org.kie.dmn.feel.runtime.functions.AbsFunction; | ||
import org.kie.dmn.feel.runtime.functions.AnyFunction; | ||
import org.kie.dmn.feel.runtime.functions.FEELFnResult; | ||
import org.kie.dmn.feel.runtime.FEELFunction.Param; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
class GenFnTypeTest { | ||
|
||
private static final AbsFunction absFunctionInstance = AbsFunction.INSTANCE; | ||
private static final AnyFunction anyFunctionInstance = AnyFunction.INSTANCE; | ||
|
||
private final GenFnType genFnType = new GenFnType( | ||
Arrays.asList(new SomeType(), new AnotherType()), | ||
new SomeType() | ||
); | ||
|
||
@Test | ||
public void testIsInstanceOfWithNoParameters() { | ||
assertThat(genFnType.isInstanceOf(absFunctionInstance)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsInstanceOfWithNonMatchingParameters() { | ||
FEELFnResult<Boolean> feelFn = anyFunctionInstance.invoke(new Object[]{Boolean.TRUE, Boolean.TRUE}); | ||
assertThat(genFnType.isInstanceOf(feelFn)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void testIsInstanceOfWithMatchingFunctionSignature() { | ||
GenFnType matchingGenFnType = new GenFnType( | ||
Arrays.asList(new SomeType(), new AnotherType()), | ||
new SomeType() | ||
); | ||
assertThat(matchingGenFnType.isInstanceOf(absFunctionInstance)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsAssignableValueWithNullValue() { | ||
assertThat(genFnType.isAssignableValue(null)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsAssignableValueWithFunction() { | ||
assertThat(genFnType.isAssignableValue(absFunctionInstance)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testConformsToWithSignature() { | ||
GenFnType matchingGenFnType = new GenFnType( | ||
Collections.singletonList(new SomeType()), | ||
new SomeType() | ||
); | ||
assertThat(genFnType.conformsTo(matchingGenFnType)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void testConformsToWithFunctionType() { | ||
assertThat(genFnType.conformsTo(BuiltInType.FUNCTION)).isTrue(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withMatchingSignatures() { | ||
List<Type> argsGen = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<Type> paramTypes = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<String> paramNames = Arrays.asList("param1", "param2"); | ||
List<List<Param>> params = createParams(paramTypes, paramNames); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isTrue(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withNonMatchingSignatures() { | ||
List<Type> argsGen = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<Type> paramTypes = Arrays.asList(new SomeType(), new YetAnotherType()); | ||
List<String> paramNames = Arrays.asList("param1", "param2"); | ||
List<List<Param>> params = createParams(paramTypes, paramNames); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isFalse(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withSignatureSizeMismatch() { | ||
List<Type> argsGen = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<Type> paramTypes = List.of(new SomeType()); | ||
List<String> paramNames = List.of("param1"); | ||
List<List<Param>> params = createParams(paramTypes, paramNames); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isFalse(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withEmptyParams() { | ||
List<Type> argsGen = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<List<Param>> params = List.of(); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isFalse(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withEmptyArgsGen() { | ||
List<Type> argsGen = List.of(); | ||
List<Type> paramTypes = Arrays.asList(new SomeType(), new AnotherType()); | ||
List<String> paramNames = Arrays.asList("param1", "param2"); | ||
List<List<Param>> params = createParams(paramTypes, paramNames); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isFalse(); | ||
} | ||
|
||
@Test | ||
void testCheckSignatures_withMatchingEmptySignature() { | ||
List<Type> argsGen = List.of(); | ||
List<List<Param>> params = List.of(); | ||
|
||
assertThat(GenFnType.checkSignatures(params, argsGen)).isFalse(); | ||
} | ||
|
||
static class SomeType implements Type { | ||
@Override | ||
public String getName() { | ||
return "SomeType"; | ||
} | ||
|
||
@Override | ||
public boolean isInstanceOf(Object o) { | ||
return o instanceof SomeType; | ||
} | ||
|
||
@Override | ||
public boolean isAssignableValue(Object value) { | ||
return value instanceof SomeType; | ||
} | ||
|
||
@Override | ||
public boolean conformsTo(Type t) { | ||
return t instanceof SomeType; | ||
} | ||
} | ||
|
||
static class AnotherType implements Type { | ||
@Override | ||
public String getName() { | ||
return "AnotherType"; | ||
} | ||
|
||
@Override | ||
public boolean isInstanceOf(Object o) { | ||
return o instanceof AnotherType; | ||
} | ||
|
||
@Override | ||
public boolean isAssignableValue(Object value) { | ||
return value instanceof AnotherType; | ||
} | ||
|
||
@Override | ||
public boolean conformsTo(Type t) { | ||
return t instanceof AnotherType; | ||
} | ||
} | ||
|
||
static class YetAnotherType implements Type { | ||
@Override | ||
public String getName() { | ||
return "YetAnotherType"; | ||
} | ||
|
||
@Override | ||
public boolean isInstanceOf(Object o) { | ||
return o instanceof YetAnotherType; | ||
} | ||
|
||
@Override | ||
public boolean isAssignableValue(Object value) { | ||
return value instanceof YetAnotherType; | ||
} | ||
|
||
@Override | ||
public boolean conformsTo(Type t) { | ||
return t instanceof YetAnotherType; | ||
} | ||
} | ||
|
||
private List<List<Param>> createParams(List<Type> types, List<String> names) { | ||
if (types.size() != names.size()) { | ||
throw new IllegalArgumentException("The number of types and names must match"); | ||
} | ||
|
||
List<List<Param>> params = new ArrayList<>(); | ||
List<Param> paramList = new ArrayList<>(); | ||
|
||
for (int i = 0; i < types.size(); i++) { | ||
paramList.add(new Param(names.get(i), types.get(i))); | ||
} | ||
|
||
params.add(paramList); | ||
return params; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the same formatting style of the code base