File tree Expand file tree Collapse file tree 3 files changed +27
-11
lines changed
compiler/src/dotty/tools/dotc/config Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -144,17 +144,16 @@ object Feature:
144144 ccEnabled && defn.ccExperimental.contains(sym)
145145
146146 def checkExperimentalDef (sym : Symbol , srcPos : SrcPos )(using Context ) =
147- if ! isExperimentalEnabled then
148- val experimentalSym =
149- if sym.hasAnnotation(defn.ExperimentalAnnot ) then sym
150- else if sym.owner.hasAnnotation(defn.ExperimentalAnnot ) then sym.owner
151- else NoSymbol
152- if ! ccException(experimentalSym) then
153- val symMsg =
154- if experimentalSym.exists
155- then i " $experimentalSym is marked @experimental "
156- else i " $sym inherits @experimental "
157- report.error(em " $symMsg and therefore may only be used in an experimental scope. " , srcPos)
147+ val experimentalSym =
148+ if sym.hasAnnotation(defn.ExperimentalAnnot ) then sym
149+ else if sym.owner.hasAnnotation(defn.ExperimentalAnnot ) then sym.owner
150+ else NoSymbol
151+ if ! ccException(experimentalSym) then
152+ val note =
153+ if experimentalSym.exists
154+ then i " $experimentalSym is marked @experimental "
155+ else i " $sym inherits @experimental "
156+ checkExperimentalFeature(" definition" , srcPos, s " \n\n $note" )
158157
159158 /** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
160159 def checkExperimentalSettings (using Context ): Unit =
Original file line number Diff line number Diff line change 1+ -- Error: tests/neg/use-experimental-def.scala:7:15 --------------------------------------------------------------------
2+ 7 |def bar: Int = foo // error
3+ | ^^^
4+ | Experimental definition may only be used under experimental mode:
5+ | 1. In a definition marked as @experimental
6+ | 2. Compiling with the -experimental compiler flag
7+ | 3. With a nightly or snapshot version of the compiler
8+ |
9+ | method foo is marked @experimental
10+ |
Original file line number Diff line number Diff line change 1+ //> using options -Yno-experimental
2+
3+ import scala .annotation .experimental
4+
5+ @ experimental def foo : Int = 1
6+
7+ def bar : Int = foo // error
You can’t perform that action at this time.
0 commit comments