-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Qute - fix assignability check when validating expressions #31112
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/TypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.qute.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
import java.math.BigDecimal; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.jandex.ArrayType; | ||
import org.jboss.jandex.ClassType; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.Indexer; | ||
import org.jboss.jandex.PrimitiveType; | ||
import org.jboss.jandex.PrimitiveType.Primitive; | ||
import org.jboss.jandex.Type; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.qute.deployment.Types.AssignableInfo; | ||
|
||
public class TypesTest { | ||
|
||
@Test | ||
public void testIsAssignableFrom() throws IOException { | ||
Index index = index(String.class, CharSequence.class, BigDecimal.class, Number.class, Serializable.class, Boolean.class, | ||
Double.class); | ||
|
||
ClassType stringType = ClassType.create(DotName.createSimple(String.class)); | ||
ClassType charSequenceType = ClassType.create(DotName.createSimple(CharSequence.class)); | ||
ClassType bigDecimalType = ClassType.create(DotName.createSimple(BigDecimal.class)); | ||
ClassType serializableType = ClassType.create(DotName.createSimple(Serializable.class)); | ||
ClassType numberType = ClassType.create(DotName.createSimple(Number.class)); | ||
Type booleanType = Types.box(Primitive.BOOLEAN); | ||
ArrayType byteArrayType = ArrayType.create(PrimitiveType.BYTE, 1); | ||
ArrayType intArrayType = ArrayType.create(PrimitiveType.INT, 1); | ||
Map<DotName, AssignableInfo> cache = new HashMap<>(); | ||
|
||
// byte[] is not assignable from String | ||
assertFalse(Types.isAssignableFrom(byteArrayType, stringType, index, cache)); | ||
// CharSequence is assignable from String | ||
assertTrue(Types.isAssignableFrom(charSequenceType, stringType, index, cache)); | ||
// String is not assignable from CharSequence | ||
assertFalse(Types.isAssignableFrom(stringType, charSequenceType, index, cache)); | ||
// String is not assignable from byte[] | ||
assertFalse(Types.isAssignableFrom(stringType, byteArrayType, index, cache)); | ||
// Object is assignable from any type | ||
assertTrue(Types.isAssignableFrom(ClassType.OBJECT_TYPE, stringType, index, cache)); | ||
// boolean is assignable from Boolean | ||
assertTrue(Types.isAssignableFrom(PrimitiveType.BOOLEAN, booleanType, index, cache)); | ||
// boolean is not assignable from double | ||
assertFalse(Types.isAssignableFrom(PrimitiveType.BOOLEAN, PrimitiveType.DOUBLE, index, cache)); | ||
// Serializable is assignable from BigDecimal | ||
assertTrue(Types.isAssignableFrom(serializableType, bigDecimalType, index, cache)); | ||
// Number is assignable from BigDecimal | ||
assertTrue(Types.isAssignableFrom(numberType, bigDecimalType, index, cache)); | ||
// byte[] is not assignable from int[] | ||
assertFalse(Types.isAssignableFrom(byteArrayType, intArrayType, index, cache)); | ||
} | ||
|
||
private static Index index(Class<?>... classes) throws IOException { | ||
Indexer indexer = new Indexer(); | ||
for (Class<?> clazz : classes) { | ||
try (InputStream stream = TypesTest.class.getClassLoader() | ||
.getResourceAsStream(clazz.getName().replace('.', '/') + ".class")) { | ||
indexer.index(stream); | ||
} | ||
} | ||
return indexer.complete(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if
type2
is an array andtype1
isn't?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.
Then the method returns
false
... see https://github.com/quarkusio/quarkus/pull/31112/files#diff-9fdf5c1c1f88f93d3b6b0d4e5f0ebb70b73d7309644b5a036ca9d012123f06e0R49.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.
OK :)