Enabling NamedTuples codebase-wide (without imports)

I would like to start using named tuples in my codebase, but I am tired of it requiring a special experimental import at the top of every file, like an infection. It discourages me (in a way that feels intentional) from using the feature alltogether because of how cumbersome it is to constantly write imports. My codebase is a private project, so I would like to enable whichever experimental features I want easily.

is there a flag I can set in build.sbt that will enable it codebase wide once and forall?

Thanks.

1 Like

Add these two to scalac options in the build tool of your choice: -experimental -language:experimental.namedTuples

Or if using scala / scala-cli use directive:

//> using options -experimental -language:experimental.namedTuples

Use scala -language:help to see list of all language feature options.
Repeated -language options are allowed

7 Likes

NamedTuples are now in the preview in 3.6, so is there an option to enable only preview features? Thanks @WojciechMazur!

NamedTuples are now in the preview in 3.6, so is there an option to enable only preview features?

In 3.6 these were still experimental, not a preview, so that’s still the only way.
In 3.7 (which would be released in first weeks of May, 3.7.0-RC3 is available) these are stable and enabled by default.

The preview features is a new concept introduced in 3.7, the first preview feature would be SIP-62 - Better Fors, all preview features would be enabled using single -preview flag. More on that would be available in the 3.7 release blogpost.

4 Likes