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

Type propagation error #19

Open
cal101 opened this issue Mar 18, 2016 · 3 comments
Open

Type propagation error #19

cal101 opened this issue Mar 18, 2016 · 3 comments

Comments

@cal101
Copy link
Collaborator

cal101 commented Mar 18, 2016

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 pushed a commit that referenced this issue Mar 20, 2016
@rpau
Copy link
Owner

rpau commented Mar 20, 2016

Did it still do not work? My test does.

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

@cal101
Copy link
Collaborator Author

cal101 commented Mar 20, 2016

I will try to build a standalone test case.
This has one: #12 ;-)

@cal101
Copy link
Collaborator Author

cal101 commented Mar 20, 2016

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);
    }

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