-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dotty with explicit nulls #6344
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
Closed
Closed
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
1c5679b
Add an explicit nulls mode to Dotty
abeln 07d1882
remove ValDefInBlockCompleter
noti0na1 9912940
add comments
noti0na1 36aca35
remove implicit check for ValDef
noti0na1 46c3e16
refine comments
noti0na1 e43963b
modify flow typing for all defs
noti0na1 4f9a437
fix flow typing when forward referred
noti0na1 19c5e40
adjust tests; add comments
noti0na1 b3c85e3
Handle Java arguments with 'Object' type in override checks
abeln 3f2e8d1
Add test for unboxed option type
abeln e2588b7
Merge branch 'master' into dotty-explicit-nulls
abeln 4fd2085
Use flatMap in opaque option test
abeln a56557f
refine comments
noti0na1 0a54fe6
Merge pull request #26 from noti0na1/dotty-explicit-nulls
noti0na1 902dc4a
Small changes according to comments
noti0na1 1168856
cache flow facts on trees
noti0na1 2d5d784
move FlowFactsOnTree to Typer; refine comments
noti0na1 f72f201
move maybeNull
noti0na1 de5241b
rename to maybeNullable
noti0na1 8e900f1
Merge pull request #27 from noti0na1/dotty-explicit-nulls-small
noti0na1 92b6c5c
Handle Java varargs during nullification
abeln feb11b0
modify methods in NullOpsDecorator
noti0na1 0000c28
rename and adjust methods
noti0na1 aabb4e1
update nullnull test
noti0na1 712e2ca
simplify the result of normNullableUnion
noti0na1 55db452
remove extra space
noti0na1 9595870
optimize widenUnion
noti0na1 7663fc2
rewrite widenUnion
noti0na1 53a88cd
further simplify widenUnion
noti0na1 fdea080
add comment
noti0na1 19925a5
Merge pull request #28 from noti0na1/dotty-explicit-nulls-ops
noti0na1 f9ca273
inline policies in JavaNullInterop
noti0na1 92095a2
remove extra braces
noti0na1 0b35a43
combine two type mapper
noti0na1 c7396db
remove toJavaNullableUnion
noti0na1 28552f5
add a helper for OrType(tp, JavaNull)
noti0na1 d4df9e7
Merge pull request #29 from noti0na1/dotty-explicit-nulls-small
noti0na1 e2c47d7
null is not allowed to be thrown; small edit to the code style
noti0na1 ec880ad
change type eq test in isNullSpace
noti0na1 513890d
edit comment
noti0na1 6c898c7
update comment on flags
noti0na1 fa43361
Merge pull request #30 from noti0na1/dotty-explicit-nulls-small
noti0na1 919f5c6
Merge remote-tracking branch 'upstream/master' into dotty-explicit-nulls
noti0na1 74e1ede
Merge pull request #31 from noti0na1/dotty-explicit-nulls
abeln 6b25d48
revert change to throwMethod; clean up if-else
noti0na1 70b5df0
Merge pull request #32 from noti0na1/dotty-explicit-nulls
noti0na1 6e92146
add notnull detect
noti0na1 9b6846e
fix cyclicref
noti0na1 e0bc5d3
Merge remote-tracking branch 'upstream/master' into dotty-explicit-nu…
noti0na1 cbb876c
change NotNull string list to ClassSymbol list
noti0na1 750dd50
ensure NotNull works for fields
noti0na1 183d237
Merge pull request #34 from noti0na1/dotty-explicit-nulls-small
abeln 0cbfa6b
Merge remote-tracking branch 'explicit-nulls/dotty-explicit-nulls' in…
noti0na1 c960acf
Optimize JavaNullInterop; add tests for Java files; remove dummy notn…
noti0na1 b0acf92
rename variables
noti0na1 9365e1b
add generic tests
noti0na1 ca62bf9
fix typos and indents
noti0na1 a49d4c3
remove redundent comment
noti0na1 8481c2a
update comments
noti0na1 ae4253a
update comments and var names
noti0na1 ad9ae9b
Merge pull request #33 from noti0na1/dotty-explicit-nulls
noti0na1 9913410
merge dotty upstream
noti0na1 313057c
Merge pull request #35 from noti0na1/dotty-explicit-nulls
abeln 3a1d17c
fix nullifying type arguements
noti0na1 303d2de
fix indent
noti0na1 9d77d64
fix typo in the test
noti0na1 cd623d4
Merge pull request #37 from noti0na1/dotty-explicit-nulls
noti0na1 54eca3c
merge upstream changes
noti0na1 8c195dc
fix syntax error
noti0na1 946a7a9
Merge pull request #38 from noti0na1/dotty-explicit-nulls
abeln 856ba31
change the way of creating ClassSymbol; add neg test for annotation
noti0na1 4cd1114
update comments
noti0na1 4a8b754
Merge pull request #41 from noti0na1/dotty-explicit-nulls
noti0na1 6d6d2ec
Merge remote-tracking branch 'upstream/master' into dotty-explicit-nulls
noti0na1 944f91d
Merge pull request #42 from noti0na1/dotty-explicit-nulls
abeln File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try AnyVal instead of Any for the parent of Null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An issue with Having
Null
underAnyVal
is thatNotNull
is harder to express. So, maybe hold off with that for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, what
NotNull
are you referring to? WithNull
underAnyVal
, a typeT
is guaranteed not to containnull
ifT <: AnyRef
. It's as simple as that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type could also be a primitive type like Int or Boolean, or a value class.
NotNull
is needed for type signatures like a Java-like map get:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.
Well TBH I'm not sure that using this kind of signature is something we would want to encourage. We want people not to use
Null
in a normal Scala program.Anyway, you can still define
NotNull
asYes, that would take longer to typecheck against, but I would certainly hope that usage of
NotNull
in a regular Scala program would be very limited, and used only when performance is so important that you're willing to deal withNull
. And if you're concerned about performance, then probably you're concerned about boxing and that means you probably don't want to accept other primitive types, so<: AnyRef
is what you would use.(Also, yes, my
NotNull
does not admit customAnyVal
classes, but for the same reasons I don't think this is a likely use case.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
Try.apply
equally flawed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but in a slightly different way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could that be fixed with:
then your example would be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivating example is code like:
It would be nice to not have to include the first case.
More concretely, in minitest, there is the line:
Option(source.getMessage).filterNot(_.isEmpty)
This fails to compile because the
Option()
returns anOption[T|Null]
, so then the_
could be null, so you can't call.isEmpty
on it. To get it to compile, we currently have to rewrite the above to:Option(source.getMessage).filterNot(_.nn.isEmpty)
I think this defeats the main purpose of
Option.apply
, which is to get rid of the possibility ofnull
by changing it toNone
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be an inference issue, not a subtyping/type hierarchy issue. We could teach type inference that when it tries to infer
A
to unifyA | Null
with someT | Null
, it should chooseA = T
instead ofA = T | Null
.