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

Add missing condition in checking synthetic apply #15362

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 9 additions & 16 deletions compiler/src/dotty/tools/dotc/transform/init/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Types._, Symbols._, Contexts._
import scala.collection.mutable

object Errors:
sealed trait Error {
sealed trait Error:
def trace: Seq[Tree]
def show(using Context): String

Expand Down Expand Up @@ -55,7 +55,7 @@ object Errors:
/** Used to underline source positions in the stack trace
* pos.source must exist
*/
private def positionMarker(pos: SourcePosition): String = {
private def positionMarker(pos: SourcePosition): String =
val trimmed = pos.lineContent.takeWhile(c => c.isWhitespace).length
val padding = pos.startColumnPadding.substring(trimmed).nn + " "
val carets =
Expand All @@ -64,48 +64,41 @@ object Errors:
else "^"

s"$padding$carets\n"
}

override def toString() = this.getClass.getName.nn
}
end Error

/** Access non-initialized field */
case class AccessNonInit(field: Symbol, trace: Seq[Tree]) extends Error {
case class AccessNonInit(field: Symbol, trace: Seq[Tree]) extends Error:
def source: Tree = trace.last
def show(using Context): String =
"Access non-initialized " + field.show + "."

override def pos(using Context): SourcePosition = field.sourcePos
}

/** Promote a value under initialization to fully-initialized */
case class PromoteError(msg: String, trace: Seq[Tree]) extends Error {
case class PromoteError(msg: String, trace: Seq[Tree]) extends Error:
def show(using Context): String = msg
}

case class AccessCold(field: Symbol, trace: Seq[Tree]) extends Error {
case class AccessCold(field: Symbol, trace: Seq[Tree]) extends Error:
def show(using Context): String =
"Access field on a value with an unknown initialization status."
}

case class CallCold(meth: Symbol, trace: Seq[Tree]) extends Error {
case class CallCold(meth: Symbol, trace: Seq[Tree]) extends Error:
def show(using Context): String =
"Call method on a value with an unknown initialization" + "."
}

case class CallUnknown(meth: Symbol, trace: Seq[Tree]) extends Error {
case class CallUnknown(meth: Symbol, trace: Seq[Tree]) extends Error:
def show(using Context): String =
val prefix = if meth.is(Flags.Method) then "Calling the external method " else "Accessing the external field"
prefix + meth.show + " may cause initialization errors" + "."
}

/** Promote a value under initialization to fully-initialized */
case class UnsafePromotion(msg: String, trace: Seq[Tree], error: Error) extends Error {
case class UnsafePromotion(msg: String, trace: Seq[Tree], error: Error) extends Error:
override def issue(using Context): Unit =
report.warning(show, this.pos)

def show(using Context): String =
msg + stacktrace + "\n" +
"Promoting the value to fully initialized failed due to the following problem:\n" +
error.show + error.stacktrace
}
Loading