Skip to content

Fix #5039: Handle null:_* as varargs parameter #6418

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

Merged
merged 1 commit into from
May 6, 2019

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@@ -556,6 +556,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
args match {
case arg :: Nil if isVarArg(arg) =>
addTyped(arg, formal)
case Typed(Literal(Constant(null)), _) :: Nil =>
addTyped(args.head, formal)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I used .head because args is of type List[Arg] and

  case (arg @ Typed(Literal(Constant(null)), _)) :: Nil =>
    addTyped(arg, formal)

would fail with

[error] 560 |                addTyped(arg, formal)
[error]     |                         ^^^
[error]     |Found:    dotty.tools.dotc.ast.Trees.Typed[dotty.tools.dotc.ast.Trees.Untyped](arg)
[error]     |Required: Arg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just reject the code? We are moving towards null-safety, it seems it's better to reject. /cc: @abeln

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not always reject it. We could pass it to a Java varargs. Not sure if someone actually uses this pattern for performance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java it is legal to pass null as the actual array of the varargs https://coderanch.com/t/631441/java/Varargs-null

@nicolasstucki nicolasstucki marked this pull request as ready for review May 2, 2019 09:46
@nicolasstucki nicolasstucki requested a review from liufengyun May 2, 2019 09:46
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolasstucki
Copy link
Contributor Author

We fix the crash with this PR. We can add new null safety checks later when we integrate non billable types

@nicolasstucki nicolasstucki merged commit a90f930 into scala:master May 6, 2019
@nicolasstucki nicolasstucki deleted the fix-#5039 branch May 6, 2019 11:16
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

Successfully merging this pull request may close these issues.

2 participants