Skip to content

Fixes to make dotc compile with capture checking #16254

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 37 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1d2e16e
Bugfix: generate same kind of MethodType when capture checking anonym…
odersky Nov 6, 2022
5496ef1
Bugfix: Avoid crash in cc/Synthetics
odersky Nov 6, 2022
65d8b19
Performance: Run capture checking transformers only if cc is enabled …
odersky Nov 6, 2022
2066efa
Enhancement: Revert automatic boxing of universal variable initializers
odersky Nov 6, 2022
f17fff9
Enhancement: Special treatment of arguments of `asInstanceOf`
odersky Nov 6, 2022
feb4c7c
Enhancement: Assume special capturing types for `eq` and `ne`
odersky Nov 6, 2022
96643ef
Bugfix: Allow all private definitions to have inferred types
odersky Nov 6, 2022
824580e
Bugfix: Avoid spurious check in RefChecks
odersky Nov 6, 2022
7740fb7
Bugfix: More lenient definition when an inferred type is OK for visib…
odersky Nov 6, 2022
4b98155
Enhancement: Don't count @constructorOnly parameters towards the self…
odersky Nov 6, 2022
b21867f
Enhancement: More lenient check for inferred self types
odersky Nov 6, 2022
4b97e1d
Enhancement: Add missing case for comparison of capturing types.
odersky Nov 6, 2022
7f0e259
Enhancement: Force all exception classes to be pure
odersky Nov 6, 2022
3964599
Tweak: Don't refine parameters of Java classes
odersky Nov 6, 2022
2ba6289
Tweak: Tweak rechecking of returns
odersky Nov 6, 2022
d157daa
Bugfix: Refine canWidenAbstract criterion
odersky Nov 6, 2022
18b8ff4
Tweak: Widen skolem types before conformity checks
odersky Nov 6, 2022
1b15fa6
Bugfix: Relax experimental inheritance criterion
odersky Nov 6, 2022
055beab
Enhancement: Introduce caps.Pure trait
odersky Nov 6, 2022
f194098
Tweak: Make root addition handler take a context
odersky Nov 6, 2022
f6e1c03
Bugfix: Fix setup of overriding symbols
odersky Nov 6, 2022
65477c5
Bugfix: Make another map an IdempotentCaptRefMap
odersky Nov 6, 2022
594aa1a
Bugfix: Fix handling for call-by-name arguments of applied types
odersky Nov 6, 2022
f8c4482
Bugfix: Make sure to restore anonymous function infos
odersky Nov 6, 2022
10c657c
Tweak: Exclude default getters from "must be explicitly defined" requ…
odersky Nov 7, 2022
c2086df
Enhancement: Treat Any as a top type for comparisons.
odersky Nov 7, 2022
ff5726c
Enhancement: Implement bounds checking
odersky Nov 7, 2022
25a4246
Enhancement: Take purity of classes into account when capture checking
odersky Nov 7, 2022
f079fe5
Enhancement: Add unsafeBoxFunArg operation.
odersky Nov 7, 2022
96bbc1d
Bugfix: Restore cached denotations of NamedTypes to their value befor…
odersky Nov 7, 2022
78dc699
Bugfix: Maintain inline context when rechecking
odersky Nov 7, 2022
2d5e981
Tweak: Avoid type ascription in uncheckedNN
odersky Nov 7, 2022
0381e2e
Enhancement: Move unsafe box/unbox ops into separate caps.unsafe module
odersky Nov 7, 2022
5d7b043
Tweak: Print Ranges like regular types
odersky Nov 7, 2022
f07dc95
Enhancement: Generalize handling of exceptions to all pure base classes
odersky Nov 7, 2022
16b5f4e
Fix typos
odersky Nov 10, 2022
dc4d6c9
Add doc comment to postCheck
odersky Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak: Tweak rechecking of returns
  • Loading branch information
odersky committed Nov 8, 2022
commit 2ba6289e98fa2d726fd8c91d26ffe88fa7ce6cb0
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,16 @@ abstract class Recheck extends Phase, SymTransformer:

val rawType = recheck(tree.expr)
val ownType = avoidMap(rawType)
checkConforms(ownType, tree.from.symbol.returnProto, tree)
// The pattern matching translation, which runs before this phase
// sometimes instantiates return types with singleton type alternatives
// but the returned expression is widened. We compensate by widening the expected
// type as well.
def widened(tp: Type): Type = tp match
case tp: SingletonType => tp.widen
case tp: AndOrType => tp.derivedAndOrType(widened(tp.tp1), widened(tp.tp2))
case tp @ AnnotatedType(tp1, ann) => tp.derivedAnnotatedType(widened(tp1), ann)
case _ => tp
checkConforms(ownType, widened(tree.from.symbol.returnProto), tree)
defn.NothingType
end recheckReturn

Expand Down
11 changes: 11 additions & 0 deletions tests/pos-custom-args/captures/cmp-singleton-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class T
class A extends T
class B extends T

def test(tp: T) =
val mapping: Map[A, String] = ???

tp match
case a: A => mapping(a) match
case s: String => B()
case null => a