44/// on items from name resolution
55module internal FSharp.Compiler.AttributeChecking
66
7+ open System
78open System.Collections .Generic
89open FSharp.Compiler .AbstractIL .IL
910open FSharp.Compiler .AbstractIL .Internal .Library
@@ -246,7 +247,6 @@ let MethInfoHasAttribute g m attribSpec minfo =
246247 |> Option.isSome
247248
248249
249-
250250/// Check IL attributes for 'ObsoleteAttribute', returning errors and warnings as data
251251let private CheckILAttributes ( g : TcGlobals ) isByrefLikeTyconRef cattrs m =
252252 let ( AttribInfo ( tref , _ )) = g.attrib_ SystemObsolete
@@ -267,9 +267,16 @@ let private CheckILAttributes (g: TcGlobals) isByrefLikeTyconRef cattrs m =
267267
268268/// Check F# attributes for 'ObsoleteAttribute', 'CompilerMessageAttribute' and 'ExperimentalAttribute',
269269/// returning errors and warnings as data
270- let CheckFSharpAttributes g attribs m =
271- if isNil attribs then CompleteD
272- else
270+ let langVersionPrefix = " --langversion:preview"
271+ let CheckFSharpAttributes ( g : TcGlobals ) attribs m =
272+ let isExperimentalAttributeDisabled ( s : string ) =
273+ if g.compilingFslib then
274+ true
275+ else
276+ g.langVersion.IsPreviewEnabled && ( s.IndexOf( langVersionPrefix, StringComparison.OrdinalIgnoreCase) >= 0 )
277+
278+ if isNil attribs then CompleteD
279+ else
273280 ( match TryFindFSharpAttribute g g.attrib_ SystemObsolete attribs with
274281 | Some( Attrib(_, _, [ AttribStringArg s ], _, _, _, _)) ->
275282 WarnD( ObsoleteWarning( s, m))
@@ -283,28 +290,30 @@ let CheckFSharpAttributes g attribs m =
283290 | None ->
284291 CompleteD
285292 ) ++ ( fun () ->
286-
293+
287294 match TryFindFSharpAttribute g g.attrib_ CompilerMessageAttribute attribs with
288- | Some( Attrib(_, _, [ AttribStringArg s ; AttribInt32Arg n ], namedArgs, _, _, _)) ->
295+ | Some( Attrib(_, _, [ AttribStringArg s ; AttribInt32Arg n ], namedArgs, _, _, _)) ->
289296 let msg = UserCompilerMessage( s, n, m)
290297 let isError =
291298 match namedArgs with
292299 | ExtractAttribNamedArg " IsError" ( AttribBoolArg v) -> v
293300 | _ -> false
294301 if isError && ( not g.compilingFslib || n <> 1204 ) then ErrorD msg else WarnD msg
295-
296302 | _ ->
297303 CompleteD
298304 ) ++ ( fun () ->
299-
305+
300306 match TryFindFSharpAttribute g g.attrib_ ExperimentalAttribute attribs with
301- | Some( Attrib(_, _, [ AttribStringArg( s) ], _, _, _, _)) ->
302- WarnD( Experimental( s, m))
303- | Some _ ->
307+ | Some( Attrib(_, _, [ AttribStringArg( s) ], _, _, _, _)) ->
308+ if isExperimentalAttributeDisabled s then
309+ CompleteD
310+ else
311+ WarnD( Experimental( s, m))
312+ | Some _ ->
304313 WarnD( Experimental( FSComp.SR.experimentalConstruct (), m))
305- | _ ->
314+ | _ ->
306315 CompleteD
307- ) ++ ( fun () ->
316+ ) ++ ( fun () ->
308317
309318 match TryFindFSharpAttribute g g.attrib_ UnverifiableAttribute attribs with
310319 | Some _ ->
0 commit comments