This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 243093 - Missing hint "Cast x to T" for the return value of lambda expressions
Summary: Missing hint "Cast x to T" for the return value of lambda expressions
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows 8
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-20 14:21 UTC by xehpuk
Modified: 2014-07-30 02:31 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description xehpuk 2014-03-20 14:21:45 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Windows 8 version 6.2 running on amd64
Java; VM; Vendor = 1.8.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70

Consider this class (and imply an import for java.util.function.Supplier):

class MissingCastHintInLambdaExpression {
    void bug() {
        Supplier<String> s = new Supplier<String>() {
            @Override
            public String get() {
                return new Object(); // "incompatible types: Object cannot be converted to String"
            }
        };
    }
}

NetBeans correctly shows a compiler error and provides the hint "Cast ...new Object(...) to String" which results in this (syntactically) correct code:

class MissingCastHintInLambdaExpression {
    void bug() {
        Supplier<String> s = new Supplier<String>() {
            @Override
            public String get() {
                return (String) new Object();
            }
        };
    }
}

When I introduce a lambda expression in the first version, it looks like this:

class MissingCastHintInLambdaExpression {
    void bug() {
        Supplier<String> s = () -> new Object(); // "incompatible types: bad return type in lambda expression", "Object cannot be converted to String"
    }
}

Again, NetBeans correctly shows a compiler error, but it does not provide a hint to insert the cast to String which – once implemented – should change the code like this:

class MissingCastHintInLambdaExpression {
    void bug() {
        Supplier<String> s = () -> (String) new Object();
    }
}
Comment 1 Svata Dedic 2014-07-17 10:27:08 UTC
Fixed in jet-main#3c5dfaac4af6
Comment 2 Quality Engineering 2014-07-30 02:31:20 UTC
Integrated into 'main-silver', will be available in build *201407300001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/3c5dfaac4af6
User: Svata Dedic <sdedic@netbeans.org>
Log: #243093: add cast hint provided for lambda expressions