@@ -131,12 +131,7 @@ object Feature:
131
131
132
132
def checkExperimentalFeature (which : String , srcPos : SrcPos , note : => String = " " )(using Context ) =
133
133
if ! isExperimentalEnabled then
134
- report.error(
135
- em """ Experimental $which may only be used under experimental mode:
136
- | 1. in a definition marked as @experimental, or
137
- | 2. compiling with the -experimental compiler flag, or
138
- | 3. with a nightly or snapshot version of the compiler. $note
139
- """ , srcPos)
134
+ report.error(experimentalUseSite(which) + note, srcPos)
140
135
141
136
private def ccException (sym : Symbol )(using Context ): Boolean =
142
137
ccEnabled && defn.ccExperimental.contains(sym)
@@ -146,12 +141,25 @@ object Feature:
146
141
if sym.hasAnnotation(defn.ExperimentalAnnot ) then sym
147
142
else if sym.owner.hasAnnotation(defn.ExperimentalAnnot ) then sym.owner
148
143
else NoSymbol
149
- if ! ccException(experimentalSym) then
150
- val note =
144
+ if ! isExperimentalEnabled && ! ccException(experimentalSym) then
145
+ val msg =
146
+ import ast .untpd .*
147
+ import Constants .Constant
148
+ experimentalSym.getAnnotation(defn.ExperimentalAnnot ).map(_.tree).collect {
149
+ case Apply (_, List (Literal (Constant (msg : String )))) => s " : $msg"
150
+ }.getOrElse(" " )
151
+ val markedExperimental =
151
152
if experimentalSym.exists
152
- then i " $experimentalSym is marked @experimental "
153
- else i " $sym inherits @experimental "
154
- checkExperimentalFeature(" definition" , srcPos, s " \n\n $note" )
153
+ then i " $experimentalSym is marked @experimental $msg"
154
+ else i " $sym inherits @experimental $msg"
155
+ report.error(markedExperimental + " \n\n " + experimentalUseSite(" definition" ), srcPos)
156
+
157
+ private def experimentalUseSite (which : String ): String =
158
+ s """ Experimental $which may only be used under experimental mode:
159
+ | 1. in a definition marked as @experimental, or
160
+ | 2. compiling with the -experimental compiler flag, or
161
+ | 3. with a nightly or snapshot version of the compiler.
162
+ | """ .stripMargin
155
163
156
164
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
157
165
def checkExperimentalSettings (using Context ): Unit =
0 commit comments