Skip to content
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

Correct the type of "this" #3659

Merged
merged 35 commits into from Sep 15, 2020
Merged

Correct the type of "this" #3659

merged 35 commits into from Sep 15, 2020

Conversation

smillst
Copy link
Member

@smillst smillst commented Sep 11, 2020

This pull request corrects the type of both implicit and explicit this references by correctly computing the enclosing type of this.

This pull request fixes two kinds of bugs:

  1. The type of Outer.this when used in an inner class. (Issues Incorrect annotations on nested class receivers #352, Treat ClassName.this like this #2208, and Framework ignores annotations on outer types #3561.)
  2. For the Initialization Checker, the type of Outer.this when used in an anonymous class declared in a constructor. (Issues Nullness Checker nested class initialization #354, part of Annonymous class in field initializer needs to treat surrounding class as under initialization #904, and False negative: Nullness Checker allows leaking @UnderInitialization this to anonymous class instance #3408)

#409 (and other duplicate issues) is a related bug in the Initialization Checker, but isn't fixed by this PR.

Closes #352, closes #354, closes #2208, closes #3266, closes #3408 and closes #3561.

Merge with typetools/checker-framework-inference#174.

smillst and others added 4 commits September 11, 2020 12:56
…anUp

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

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

Looks reasonable, but tests are not yet passing.

@mernst mernst assigned smillst and unassigned mernst Sep 12, 2020
@smillst smillst merged commit 0d1de3b into typetools:master Sep 15, 2020
@smillst smillst deleted the receiverCleanUp branch September 15, 2020 01:38
smillst added a commit that referenced this pull request Oct 20, 2020
Defaulting rules for the primary annotation of an intersection type:
1. One or more of the bounds have an explicit annotation: the default annotation is the first explicit annotation.  (I tried making the default the glb of the (explicit or defaulted) annotations on the bounds, but I found this confusing in the case of casts.  We can discuss this further.)
2. Zero bounds have an explicit annotation: the default annotation of the location is applied.  (So, either explicit upper bound defaults, or for casts, the annotation of the cast expression.)

Warning:
If any explicit annotation on a bound is not the same as the primary annotation, then a warning is issued.  (I was going to put this in a separate pull request, but it needs to be in this one so that the test cases are easier to understand.)  

Changes to AnnotatedIntersectionType:
1. Adding a primary annotation to an intersection type causes that annotation to be copied to its bounds.  This is similar to what happens when an annotation is added to a type variable.
2. New method `getBounds` returns a list of the bounds of the intersection type.  (This used to be done via `directSuperTypes` method.
3.  The bounds can be any AnnotatedTypeMirror if the intersection arises from capture conversion.

 Fixes #868; Fixes #3349; Fixes #3362; Fixes #3659.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment