I came across a situation where the following was not a compile time error, but did give rise to a runtime error unless I reordered the definition of port
and uriScheme
(I’ll note that IntelliJ did warn me of a “suspicious forward reference”):
implicit val port: Rx[Port] = (currentApiUri |@| uriScheme).map{ (curUri, curSchm) =>
Option(curUri.getPort) match {
case Some(prt) => if (prt < 0) Port(schemeToDefaultPort(curSchm.scheme)) else Port(prt)
case None => Port(defaultPort)
}
}
implicit val uriScheme: Rx[UriScheme] = currentApiUri.map{ curUri =>
Option(curUri.getScheme) match {
case Some(scheme) => UriScheme(scheme)
case None => UriScheme(defaultScheme)
}
}
Is there a scalac flag that will not generate additional code, but will turn such non-lazy forward references into compile-time errors?