rpau / javalang-compiler

Java compiler elements (symbol and type tables) to perform code semantic analysis
GNU Lesser General Public License v3.0
10 stars 4 forks source link

Type propagation error #19

Open cal101 opened 8 years ago

cal101 commented 8 years ago

Another Easymock issue where the type parameter is lost:

public void doFile(File f) {

    }
...
public static <T> T capture(final Capture<T> captured) {
        reportMatcher(new Captures<T>(captured));
        return null;
    }
...
protected static class FileContentCapture extends Capture<File> {
}
...
public class Capture<T> implements Serializable {
 public T getValue() {
 }
}
...
void x() {
        final FileContentCapture capturedFileContent = new FileContentCapture();

 doFile(capture(capturedFileContent));
}

Results in:

Caused by: java.lang.Exception: Ops! The method call doFile(capture(capturedFileContent)) is not resolved. The scope is [empty] , and the args are : [ float]
rpau commented 8 years ago

Did it still do not work? My test does.

Could you provide me the list of different "capture" methods the class has?

cal101 commented 8 years ago

I will try to build a standalone test case. This has one: https://github.com/rpau/javalang-compiler/issues/12 ;-)

cal101 commented 8 years ago

I am able to reproduce the issue using EasyMock 3.1. Look at the javadoc I copied. That explains the problems to do a test case ...

Maybe walkmod should be able to deal with that because libraries may have this. But maybe it is an edge case that is seldom.

The class contains

    /**
     * Expect any object but captures it for later use.
     * 
     * @param <T>
     *            Type of the captured object
     * @param captured
     *            Where the parameter is captured
     * @return <code>null</code>
     */
    public static <T> T capture(final Capture<T> captured) {
        reportMatcher(new Captures<T>(captured));
        return null;
    }

    /**
     * Expect any boolean but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static boolean capture(final Capture<Boolean> captured) {
        return captureBoolean(captured);
    }

    /**
     * Expect any int but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static int capture(final Capture<Integer> captured) {
        return captureInt(captured);
    }

    /**
     * Expect any long but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static long capture(final Capture<Long> captured) {
        return captureLong(captured);
    }

    /**
     * Expect any float but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static float capture(final Capture<Float> captured) {
        return captureFloat(captured);
    }

    /**
     * Expect any double but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static double capture(final Capture<Double> captured) {
        return captureDouble(captured);
    }

    /**
     * Expect any byte but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static byte capture(final Capture<Byte> captured) {
        return captureByte(captured);
    }

    /**
     * Expect any char but captures it for later use.
     * 
     * @param captured
     *            Where the parameter is captured
     * @return <code>0</code>
     * 
     * @deprecated Because of harder erasure enforcement, doesn't compile in
     *             Java 7
     */
    @Deprecated
    public static char capture(final Capture<Character> captured) {
        return captureChar(captured);
    }