Commit Graph

86 Commits

Author SHA1 Message Date
Kirill Rakhman eae72eac54 [FIR] Fix substitution of Java arrays enhanced for warning
... w.r.t the variance of their type arguments.
Because `Object[]` is represented as `Array<Any>..Array<out Any>?`,
when we substitute, we can't just take the upper bound because it
changes the variance of the type agument.
Instead, we construct a flexible type and use both bounds, like with
collections with flexible mutability.

#KT-65246 Fixed
2024-02-15 10:48:56 +00:00
Kirill Rakhman 9e72482f09 [FIR] Fix infinite loop in attribute substitution
#KT-65318 Fixed
2024-01-31 08:55:22 +00:00
Kirill Rakhman e91e9d8ca8 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209

(cherry picked from commit 371b1eb3d5)
2024-01-18 08:27:10 +00:00
Kirill Rakhman 121536d2e5 Revert "[FIR] Don't lose error level enhancements in warning-level-enhanced arguments"
This reverts commit 371b1eb3d5.
2024-01-16 09:14:21 +01:00
Kirill Rakhman 371b1eb3d5 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209
2024-01-15 12:23:26 +00:00
Kirill Rakhman 31256e259e [FIR] Fix lower bound of flexible type variable not becoming DNN in warning-severity case
The bug was introduced as part of the implementation for Java
nullability warnings.

#KT-58933 Fixed
2023-11-24 11:00:10 +00:00
Mikhail Glukhikh 1eacd5efc2 K1/K2: support org.jspecify.annotations.NonNull in Java interop
#KT-62352 Fixed
2023-11-16 11:13:44 +00:00
Kirill Rakhman 2005446296 [FIR] Preserve enhanced mutability when nullability was enhanced for warning
#KT-56989
2023-11-15 08:43:55 +00:00
Kirill Rakhman a63ec9efdc [FIR] Implement warnings for java nullability upper bound violation 2023-11-15 08:43:55 +00:00
Kirill Rakhman 2df1e9dde6 [FIR] Implement warnings for java nullability type mismatch on override
#KT-56989
2023-11-15 08:43:55 +00:00
Kirill Rakhman a6fdeeb7df [FIR] Implement warnings for java nullability type mismatch
#KT-56989
2023-11-15 08:43:55 +00:00
Mikhail Glukhikh 87904fd766 AbstractTypeChecker: don't create forks for identical supertypes
The main reason of this commit is the fact that it makes no sense
to create type checker forks in case of two or more types which equal
each other.

Also, this commit fixes the test taken from KT-59514
(see interconnectedGenerics.kt test changed in this commit).
In this particular case we have a subType of C.WithL<Pr!, En<Pr>!>,
and a superType of R<T> with a superType constructor R.
In findCorrespondingSupertypes we get *two* similar supertypes here,
both have a string representation of:
R<Il<@EnhancedNullability En<Pr>!>!>.
If we create two forks because of it, we get NEW_INFERENCE_ERROR
with the following subtyping violation:
Il<@EnhancedNullability En<Pr>!>! <: En<Pr>!.
NEW_INFERENCE_ERROR happens because we make a redundant fork in that case,
but the forks should still work despite it (see KT-62333).

These two types appear due to the content of FirCorrespondingSupertypeCache.
For a key C.WithL and a superType R it stores the following pair of supertypes:
- R<Il<@EnhancedNullability S>!>
- R<Il<(@EnhancedNullability S & Any, @EnhancedNullability S?)>!>
After substitution of S to En<Pr>! they become similar.
NB: if we change jspecify severity level from strict to warn,
then 'R<Il<(S & Any, S?)>!>' is the only remaining supertype,
and @EnhancedNullability annotation is no more in use.

The type hierarchy in this example looks like:
WithL<T, S> <: CanWithB<T, S>, R.F<S, Il<S>>
CanWithB<T, S> <: R.F<S, Il<S>>
R.F<S, Il<S>> <: R<Il<S>>

So R is reachable by two different ways, via CanWithB and directly via R.F.

#KT-59514 Fixed
2023-10-05 11:29:18 +00:00
Mikhail Glukhikh d4ec088afe K2: add reproduction for KT-59514 2023-10-05 11:29:18 +00:00
Denis.Zharkov c3ac2e44a0 Adjust test data for enabling ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
^KT-55388 Fixed
2023-05-15 10:43:19 +00:00
Denis.Zharkov 3e2f8b834c K2: Replicate K1 enhancement behavior for warning-mode top-level types
^KT-56657 Fixed
^KT-57307 Related
2023-03-17 08:52:31 +00:00
Denis.Zharkov 644391a8e0 K2: Fix Java enhancement when jsr305.jar is not in classpath
In that case, when loading Java, we just remember the name of `@Nonnull`
argument (javax.annotation.meta.When), and then use it during enhancement

^KT-56656 Fixed
2023-03-16 14:43:05 +00:00
Denis.Zharkov 157c260fda Add test data with current behavior for KT-56656 2023-03-16 14:43:05 +00:00
Kevin Bourrillion 2694bdeb92 Change to use new JSpecify package location. 2022-12-27 11:10:59 +00:00
Kevin Bourrillion 671480ce1a Duplicate this entire test suite to jspecifyOld before changing the package locations in jspecify. 2022-12-27 11:10:59 +00:00
Denis.Zharkov cd0d6d2773 Adjust test data for postponing ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
^KT-55357 Related
^KT-36770 Related
2022-12-12 11:39:04 +00:00
pyos 6c6d653e85 FE: don't lose annotations on Java primitive arrays
but only use them to enhance for warnings for now.

^KT-48861 Fixed
2022-10-26 09:33:40 +02:00
Mikhail Glukhikh 730a5d1a88 FIR: introduce Java vs Kotlin class conflicts checker #KT-44441 Fixed 2022-07-04 13:28:58 +00:00
Ilya Chernikov bb996c1b27 Switch kotlin version to 1.8
with appropriate fixes in testdata, tests and other
places.
2022-06-29 10:20:30 +02:00
Jinseong Jeon a2da690afd Test: add java source files as JavaSourceRoot
so that those can be properly populated in SingleJavaRootsIndex
2022-06-16 22:14:17 +02:00
Denis.Zharkov f70ae2df3a FIR: Refine inference constraints when type variable in flexible position
That issue might be fixed via changing
TypeVariableMarker.shouldBeFlexible at ConeConstraintSystemUtilContext
but this and some other tricks have been added because of incorrect
handling of constraints where type variable has a flexible bound

^KT-51168 Fixed
2022-05-19 16:53:59 +00:00
Ivan Kochurkin c6f52893fb [FIR] Fix inconsistent RETURN_TYPE_MISMATCH and TYPE_MISMATCH reporting on functions and properties
^KT-51203 Fixed
2022-04-05 15:50:43 +00:00
Mikhail Glukhikh 53d6ac24e5 Switch kotlin version to 1.7
* Change 1.6 to 1.7 constants
* Fix SAFE_CALL_WILL_CHANGE_NULLABILITY for testData
* Change EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_WARNING to EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR
* Change NON_EXHAUSTIVE_WHEN_STATEMENT to NO_ELSE_IN_WHEN
* Fix testData for SafeCallsAreAlwaysNullable
* Change T -> T & Any in test dumps
* Change INVALID_CHARACTERS_NATIVE_WARNING -> INVALID_CHARACTERS_NATIVE_ERROR
* TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_WARNING -> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR
2022-02-25 11:46:27 +00:00
Vladimir Dolzhenko 918a91dbdf Escape special names with backticks in test data
#KT-51248
2022-02-10 21:20:47 +00:00
Victor Petukhov 1f1b5256b0 Postpone type enhancement improvements till 1.7 due to some found broken cases unmarked by warnings before
^KT-49378 Fixed
2022-01-12 15:58:50 +03:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
Ivan Kochurkin d0a4ca199d [FIR] Add UNCHECKED_CAST
Regenerate diagnostics code
2021-11-12 15:20:45 +03:00
Dmitriy Novozhilov f26059a7d3 [FE] Add clear warning about future changes about nullability of safe call with non nullable receiver
^KT-46860
2021-10-27 16:28:37 +03:00
Victor Petukhov e0a4704c21 Revert "Make freshly substituted type variables def not nullable if they come from not null type parameter"
This reverts commit 41936a790b37bef45d7e7dad851856ea1750ef01.
2021-10-26 19:37:58 +03:00
Victor Petukhov 836c6b280d Make freshly substituted type variables def not nullable if they come from not null type parameter
^KT-48778 Fixed
2021-10-26 19:37:57 +03:00
Victor Petukhov d015d3bc0e Don't enhance previously erased value parameters for jspecify strict mode
^KT-48261 Fixed
2021-10-26 19:37:55 +03:00
Victor Petukhov b957831683 Use WarningAwareUpperBoundChecker independently
^KT-47920 Fixed
^KT-48290 Fixed
2021-09-30 20:08:58 +03:00
Victor Petukhov 70d70b9042 Use warn mode by default for jspecify nullability annotations in 1.6
^KT-48851 Fixed
2021-09-30 20:08:35 +03:00
Denis.Zharkov f7ef551f99 Report warnings on overrides with wrong types nullability
^KT-48899 Fixed
2021-09-30 14:36:26 +03:00
Denis.Zharkov 9ac29e0714 Fix enhancement when mixing TYPE_USE and non-TYPE_USE annotations 2021-09-28 22:59:18 +03:00
pyos 94402ba488 FE: prefer enhancements for errors over enhancements for warnings 2021-09-08 16:54:17 +03:00
pyos 8f699248f1 FE: force flexibility on unannotated ?
TODO: unify this code with FIR

 #KT-48515 Fixed
2021-09-08 16:54:17 +03:00
pyos afa1d18cc2 FE: in NullMarked scope, enhance T! to at least T
#KT-44436 Fixed
2021-09-08 16:54:17 +03:00
pyos f793afbfea FE: do not enhance ? into ? extends @NotNull Object in JSR-305
This is already done in jspecify and makes more sense anyway.
2021-09-08 16:54:17 +03:00
pyos 9bb7a29baa FIR: disregard enhancements for warnings
Warnings are not implemented yet, so don't produce errors either.
2021-09-06 13:11:16 +03:00
pyos 2847de10ac FIR: enhance Java super types 2021-09-06 13:11:09 +03:00
pyos 03304bce96 FIR: enhance Java type parameter bounds
This also fixes handling of self-recursive types.

TODO: fix jspecify/{strict,warn}Mode/Captured.fir.kt
2021-09-06 13:11:08 +03:00
pyos e2a48d3945 FIR: use frontend-independent Java type qualifier computation 2021-09-06 13:11:07 +03:00
pyos 5704dffdbe FIR: attach annotations to Java-converted cone types 2021-09-06 13:11:03 +03:00
pyos 5355d04553 FIR: enhance in/out-variant type arguments 2021-09-06 13:11:03 +03:00
pyos 8e122397b0 FIR: fix type index computation during enhancement
1. in/out type parameters count;
2. star projections take up 1 space in the tree.
2021-09-06 13:11:02 +03:00