Skip to content

Warning when assigning null to Unit #18722

Closed
@kavedaa

Description

@kavedaa

Compiler version

3.3.0

Minimized example

scala> val a: Unit = null

Output Error/Warning message

1 warning found
-- [E129] Potential Issue Warning: ---------------------------------------------
1 |val a: Unit = null
  |              ^^^^
  |A pure expression does nothing in statement position; you may be omitting necessary parentheses
  |
  | longer explanation available when compiling with `-explain`
val a: Unit = ()

Why this Error/Warning was not helpful

The message was unhelpful because...

...it's hard to understand why it is relevant in this scenario. I initially thought that it's perhaps not allowed to assign null to a value of Unit type, but since it's just a warning and not an error, then I guess it is. So I don't really understand at all why this warning appears here.

Suggested improvement

It could be made more helpful by...

...not giving a warning at all, or at least changing the explanation if it's actually a legitimate warning.

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions