Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created July 5, 2021 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xuwei-k/ebe068140454d50afdc5a4fd4b98b7b7 to your computer and use it in GitHub Desktop.
Save xuwei-k/ebe068140454d50afdc5a4fd4b98b7b7 to your computer and use it in GitHub Desktop.
import dotty.tools.dotc.ast.tpd.TypeTree
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols.defn
import dotty.tools.dotc.plugins.{PluginPhase, StandardPlugin}
import dotty.tools.dotc.typer.FrontEnd
import dotty.tools.dotc.report
class InferenceMatchablePlugin extends StandardPlugin {
override def name = "inference-matchable-plugin"
override def description = "warn Matchable"
override def init(options: List[String]): List[PluginPhase] = {
(new InferenceMatchablePhase()) :: Nil
}
}
class InferenceMatchablePhase extends PluginPhase {
override def phaseName = "inference-matchable"
override val runsAfter = Set(FrontEnd.name)
override def prepareForTypeTree(tree: TypeTree)(using context: Context): Context = {
if (tree.tpe == defn.MatchableType) {
report.warning("Matchableに推論されてるぞ!!!", tree.srcPos)
}
context
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment