-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Topic/modifier lockdown #3
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
Conversation
Notable omissions are ValDef and DefDef, which are subclassed by the empty variety. Final classes are easier for the reader to reason about and enable additional static analysis by the compiler. As an example of the latter, scala> trait T defined trait T scala> Tuple1(0) match { case _: T => true; case _ => false } res0: Boolean = false scala> final case class T1[A](a: A) defined class T1 scala> T1(0) match { case _: T => true; case _ => false } <console>:11: error: scrutinee is incompatible with pattern type; found : T required: T1[Int] T1(0) match { case _: T => true; case _ => false }
This commit exposes a number of inexhaustive matches: [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/Trees.scala:716: match may not be exhaustive. [warn] It would fail on the following inputs: Function(_, _), GenericApply(), ModuleDef(_, _, _), TypedSplice() [warn] def transform(tree: Tree[T], c: C): Tree[T] = tree match { [warn] ^ [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/Trees.scala:870: match may not be exhaustive. [warn] It would fail on the following inputs: Function(_, _), GenericApply(), ModuleDef(_, _, _), TypedSplice() [warn] def foldOver(x: T, tree: Tree[U]): T = tree match { [warn] ^ [warn] two warnings found [info] Compiling 52 Scala sources to /Users/jason/code/dotty/target/scala-2.10/classes... [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/PluggableTransformers.scala:80: match may not be exhaustive. [warn] It would fail on the following inputs: Alternative(_), AndTypeTree(_, _), Annotated(_, _), AppliedTypeTree(_, _), Assign(_, _), Bind(_, _), Block(_, _), CaseDef(_, _, _), ClassDef(_, _, _, _), DefDef(_, _, _, _, _, _), EmptyTree(), EmptyValDef(), Function(_, _), GenericApply(), If(_, _, _), Import(_, _), Literal(_), Match(_, _), ModuleDef(_, _, _), NamedArg(_, _), New(_), OrTypeTree(_, _), PackageDef(_, _), Pair(_, _), RefineTypeTree(_, _), Return(_, _), SelectFromTypeTree(_, _), SeqLiteral(_, _), Shared(_), SingletonTypeTree(_), Super(_, _), Template(_, _, _), This(_), Throw(_), Tree(), Try(_, _, _), TypeBoundsTree(_, _), TypeDef(_, _, _), TypeTree(_), Typed(_, _), TypedSplice(), UnApply(_, _) [warn] protected def postProcess(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match { [warn] ^ [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/Trees.scala:716: match may not be exhaustive. [warn] It would fail on the following inputs: Function(_, _), GenericApply(), ModuleDef(_, _, _), TypedSplice() [warn] def transform(tree: Tree[T], c: C): Tree[T] = tree match { [warn] ^ [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/Trees.scala:870: match may not be exhaustive. [warn] It would fail on the following inputs: Function(_, _), GenericApply(), ModuleDef(_, _, _), TypedSplice() [warn] def foldOver(x: T, tree: Tree[U]): T = tree match { [warn] ^ [warn] /Users/jason/code/dotty/src/dotty/tools/dotc/core/TypedTrees.scala:359: match may not be exhaustive. [warn] It would fail on the following inputs: EmptyTree(), GenericApply(), Try(_, _, _) [warn] def checkType(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match { [warn]
Perhaps controversially seals the hierarchy and as a consequence moves two types from the unpickler into Types.scala.
- Introduce a marker trait for Tree[Nothing] nodes, and use this in TreeAccumulator. - seal GenericApply - Make the match demo plugin transformer @unchecked - Add tree checking for Try - Match on EmptyTree() rather than tpd.EmptyTree
- info was calling itself, rather than the field _info - tryComplete must interrogate and set the Locked bit through the raw _flags.
I guess this won't merge cleanly any more. Also my checking for |
@DarkDimius I'll close this one to as it will be well and truly out of date. But maybe someone will be inspired to hold the torch of privacy/finality/sealedness in dotty for me? You will appreciate it as the code base grows larger. |
Oh, and the inliner likes finality, too! |
…debug Add returning real line of error in source file of snippet for snippet scaladoc compiler
`given ... with` or `given ... = new { ... }` kinds of definitions now follow the old rules. This allows recursive `given...with` definitions as they are found in protoQuill. We still have the old check in a later phase against directly recursive methods. Of the three loops in the original i15474 we now detect #2 and #3 with new new restrictions. #1 slips through since it is a loop involving a `given...with` instance of `Conversion`, but is caught later with the recursive method check. Previously tests #1 and #3 were detected with the recursive methods check and #2 slipped through altogether. The new rules are enough for defining simple givens with `=` without fear of looping.
`given ... with` or `given ... = new { ... }` kinds of definitions now follow the old rules. This allows recursive `given...with` definitions as they are found in protoQuill. We still have the old check in a later phase against directly recursive methods. Of the three loops in the original i15474 we now detect #2 and #3 with new new restrictions. #1 slips through since it is a loop involving a `given...with` instance of `Conversion`, but is caught later with the recursive method check. Previously tests #1 and #3 were detected with the recursive methods check and #2 slipped through altogether. The new rules are enough for defining simple givens with `=` without fear of looping.
Backport "Add better error reporting for inlined non-immutable paths" to LTS
I propose that we make a more concerted effort to keep things final/sealed; this PR does this across the board. It's easy enough to open things up later on, until then we can profit from better pattern match analysis, notification of non-sensical equality tests, and, last but not least, less to think about when reasoning about the code.
As a bonus, the exercise uncovered two compiler bugs: SI-7171 and SI-7172.
The parts that warrant closer review:
UntypedTreeMarker
in 4598e8c.Try
, and ignorance ofUntypedTree
s inTreeTransformer
andTreeAccumulator
.lastDenot
and_typeParams
.Type
, and therefore move two type nodes from the unpickler to Types.scalaReview by @odersky, if you like we can chat about this on Tuesday.