Skip to content
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

bug in getType of X.class when X is primitive #371

Closed
monperrus opened this issue Oct 12, 2015 · 3 comments
Closed

bug in getType of X.class when X is primitive #371

monperrus opened this issue Oct 12, 2015 · 3 comments

Comments

@monperrus
Copy link
Collaborator

"short.class".getType().isPrimitive() returns true, it should return false because it is a Class object

same bug for int.class, etc.

@GerardPaligot
Copy link
Contributor

What is "short.class"?

@monperrus
Copy link
Collaborator Author

Here is the expected behavior

        Factory factory = TestUtils.createFactory();
        CtClass<?> clazz = factory
                .Code()
                .createCodeSnippetStatement(
                        "" + "class X {" + "public void foo() {"
                                + " Class klass=null;"
                                + "  boolean x= (klass == short.class);"
                                + "}};")
                .compile();
        CtMethod<?> foo = (CtMethod<?>) clazz.getMethods().toArray()[0];

        CtBlock<?> body = foo.getBody();
        CtLocalVariable<?> ass = body.getStatement(1);
        CtBinaryOperator<?> op = (CtBinaryOperator<?>) ass.getDefaultExpression();      
        assertEquals("Class", op.getLeftHandOperand().getType().getSimpleName());
        assertFalse(op.getLeftHandOperand().getType().isPrimitive());
        assertEquals("Class", op.getRightHandOperand().getType().getSimpleName());
        assertFalse(op.getRightHandOperand().getType().isPrimitive());

@monperrus
Copy link
Collaborator Author

Slightly modified the test case

it's fun, #349, #346 and this one are actually quite related

@monperrus monperrus changed the title bug in isPrimitive bug in getType of X.class when X is primitive Oct 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants