redhat-developer / redhat-developer/vscode-java

Return null through ternary operator does not give Type mismatch error

オープン
#436 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug compile upstream
主要言語
TypeScript
スター
2.3k
フォーク
546
平均マージ
20時間 1分
マージ済み PR(30日)
11

説明

Returning null through a ternary operator does not give Type mismatch error. It should.

Code 1:

public double getValue() {
    return null;
}

null is error-underlined with the error [Java] Type mismatch: cannot convert from null to double.
image

Code 2:

public double getValue() {
    return value == null ? null : Double.parseDouble(value);
}

No errors shown on the returned null.
image

Code 3:

public double getValue() {
    if (value == null)
        return null;
    else
        return Double.parseDouble(value);
}

Same error:
image

Environment
  • Operating System: Windows 10 x64
  • JDK version: 8
  • Visual Studio Code version: 1.20.0
  • Java extension version: 0.18.1
Steps To Reproduce
  1. Make code shown.
  2. Look for error.
Current Result

Code 1 & 3 shows error. Code 2 doesn't.

Expected Result

All Code blocks should show error.

Additional Information

Please let me know if you need any logs or anything.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず Java 拡張機能で Code 1、Code 2、Code 3 を再現し、三項形式と if/else 形式の診断を比較します。Java 言語サポートが return 式をどのように解析するかを追跡し、三項の場合に他の例と同じ型の不一致が報告されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
compilers, devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。