Skip to content

Commit 59c7318

Browse files
KevinRansombaronfel
authored andcommitted
Allow --langversion:preview to disable ExperimentalAttribut warning. (#8042)
* Merge issues * More attributes * Experimental Attribute * literally the message * .fsi and [<Literal>] don't mix with lkg compiler.
1 parent 8d48015 commit 59c7318

File tree

6 files changed

+130
-45
lines changed

6 files changed

+130
-45
lines changed

src/fsharp/AttributeChecking.fs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// on items from name resolution
55
module internal FSharp.Compiler.AttributeChecking
66

7+
open System
78
open System.Collections.Generic
89
open FSharp.Compiler.AbstractIL.IL
910
open 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
251251
let 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 _ ->

src/fsharp/FSharp.Core/FSharp.Core.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AllowCrossTargeting>true</AllowCrossTargeting>
1111
<DefineConstants>$(DefineConstants);FSHARP_CORE</DefineConstants>
1212
<DefineConstants Condition="'$(Configuration)' == 'Proto'">BUILDING_WITH_LKG;$(DefineConstants)</DefineConstants>
13-
<OtherFlags>$(OtherFlags) --warnon:1182 --compiling-fslib --compiling-fslib-40 --maxerrors:20 --extraoptimizationloops:1</OtherFlags>
13+
<OtherFlags>$(OtherFlags) --warnon:1182 --compiling-fslib --compiling-fslib-40 --maxerrors:20 --extraoptimizationloops:1 --nowarn:57</OtherFlags>
1414
<Tailcalls>true</Tailcalls> <!-- .tail annotations always emitted for this binary, even in debug mode -->
1515
<NGenBinary>true</NGenBinary>
1616
</PropertyGroup>

0 commit comments

Comments
 (0)