Local Variable Type Inference - prototype
Robert Field
robert.field at oracle.com
Fri Mar 11 08:01:03 UTC 2016
Patch to fix this attached.
Apply as desired.
-Robert
On 03/10/16 15:41, Maurizio Cimadamore wrote:
>
>
> On 10/03/16 22:55, Robert Field wrote:
>>
>> On 03/10/16 14:21, Remi Forax wrote:
>>> At least, jshell need some tweaks :)
>>
>> Yes, it will. Thanks Remi!
>>
>> It will need the analysis pass of the compiler run so that the type
>> can be determined. Variables are implemented as fields.
>>
>> Is this something I should work on now?
> One question for you Robert: currently javac does not parse 'var' as a
> special Token - as doing that requires even more jshell changes; I'm
> happy to leave the code as is, but if, when hacking on the jshell
> side, you discover that a VAR token would be useful please let me know.
>
> Maurizio
>>
>> -Robert
>>
>>>
>>> $ /usr/jdk/jdk-9/bin/java
>>> -Xbootclasspath/p:langtools/dist/lib/jdk.compiler.jar:langtools/dist/lib/jdk.jshell.jar:langtools/dist/lib/jdk.internal.le.jar:langtools/dist/lib/jdk.jdi.jar
>>> jdk.internal.jshell.tool.JShellTool
>>> | Welcome to JShell -- Version 9-internal
>>> | Type /help for help
>>>
>>> -> void m() {
>>>>> var a = 3;
>>>>> }
>>> | Added method m()
>>>
>>> -> m()
>>>
>>> -> var a = 3;
>>> Exception in thread "main"
>>> java.lang.StringIndexOutOfBoundsException: begin -1, end -1, length 10
>>> at java.lang.String.checkBoundsBeginEnd(String.java:3122)
>>> at java.lang.String.substring(String.java:1910)
>>> at jdk.jshell.Wrap$Range.part(Wrap.java:168)
>>> at jdk.jshell.Wrap$RangeWrap.<init>(Wrap.java:350)
>>> at jdk.jshell.Wrap.varWrap(Wrap.java:97)
>>> at jdk.jshell.Eval.processVariables(Eval.java:227)
>>> at jdk.jshell.Eval.eval(Eval.java:116)
>>> at jdk.jshell.JShell.eval(JShell.java:355)
>>> at
>>> jdk.internal.jshell.tool.JShellTool.processCompleteSource(JShellTool.java:1923)
>>> at
>>> jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:1911)
>>> at
>>> jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:652)
>>> at jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:632)
>>> at jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:427)
>>> at jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:400)
>>> at jdk.internal.jshell.tool.JShellTool.main(JShellTool.java:390)
>>>
>>> Rémi
>>>
>>> ----- Mail original -----
>>>> De: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
>>>> À: platform-jep-discuss at openjdk.java.net
>>>> Envoyé: Jeudi 10 Mars 2016 15:48:25
>>>> Objet: Local Variable Type Inference - prototype
>>>>
>>>> Hi,
>>>> I've pushed the first iteration of the local variable type inference
>>>> prototype in the sandbox repository[1]. For those willing and brave
>>>> enough to experiment, the branch name is "JEP-286-branch". We are also
>>>> working to get some ready-made binary snapshots out of the door and
>>>> hope
>>>> to have an update on that soon.
>>>>
>>>> This first iteration supports the 'var-only' syntax style:
>>>>
>>>> var s = "Hello!";
>>>>
>>>> That is, the type of 's' is inferred from the initializer, and no
>>>> special assumption is made about mutability.
>>>>
>>>> Please share your experience with the prototype. For comments on this
>>>> feature please refer to the survey[2] that Brian posted few days ago.
>>>>
>>>> Maurizio
>>>>
>>>> [1] - http://cr.openjdk.java.net/~chegar/docs/sandbox.html
>>>> [2] -
>>>> http://mail.openjdk.java.net/pipermail/platform-jep-discuss/2016-March/000037.html
>>>>
>>>>
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: varJShell.diff
Type: text/x-patch
Size: 7793 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/platform-jep-discuss/attachments/20160311/82941dbd/varJShell.diff>
More information about the platform-jep-discuss
mailing list