Closed
Description
The CompilerInterface
implementation has its Term
defined to be a Tree
:
The fact that a Term
can be any tree at all makes the interface unsafe: non-terms may potentially be returned in place of terms when matching on trees. Implementing runtime checks is performance-costly – however we can implement such checks under a separate compiler flag and run them from the CI.
One possible implementation would involve a wrapper around the standard compiler interface:
class CheckingCompilerInterface(val ci: CompilerInterface)
export ci._
def matchStatement(tree: Tree)(given ctx: Context): Option[Statement] =
verifyStatement(ci.matchStatement(tree))
/* ... */
The verifyStatement
method above should do the following:
- Call the more specific matchers of all the subtypes of
Statement
- Check that exactly one of them returns a
Some
See #7503 for an example (test case) of where things go wrong without such checks.