Stefan Zeiger
Stefan Zeiger
The `cfg` annotation (or "attribute" in Rust) conditionally enables a piece of code (where an attribute is allowed, e.g. a function definition but not arbitrary places). In Scala it could...
A possible way to avoid the namer issue (especially at the top level) without too much complexity would be a new annotation-like syntax like `@if(...)`. This would also allow us...
- In the scheme with the simple predicate language more complex predicates like `binaryVersion > 2.13` need to be split up into a flag that can be checked by the...
> But for example if I want to add a parent conditionally (and not extend anything in the other case) You can always extend `AnyRef` or `Any`. This doesn't work...
Here's my prototype so far: https://github.com/szeiger/scala/tree/wip/preprocessor I'm not quite happy with the set-based key/value checks. It doesn't feel correct with Scala syntax. Supporting imports will need a bit of refactoring...
I assume it's trivial to implement but didn't get around to testing it yet.
Looks like the restriction on disallowing annotations in general for package objects is intentional: https://www.scala-lang.org/files/archive/spec/2.13/09-top-level-definitions.html#compilation-units. But since `@if` is not a real annotation we can special-case it for package objects...
The latest update supports imports, package objects and annotated expressions.
Here's a version of scala-collection-compat that does all the conditional compilation with the proprocessor: https://github.com/szeiger/scala-collection-compat/tree/wip/preprocessor-test. This shows the limits of what is possible. In practice I would probably keep 2.13...
> How do you envision that the code editing and navigation experience would work in IDEs for conditionally compiled statements? The same way that different source folders work. An IDE...