Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10829,8 +10829,10 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
let conditionalCallDefineOpt = TryFindTyconRefStringAttribute cenv.g mAttr cenv.g.attrib_ConditionalAttribute tcref

match conditionalCallDefineOpt with
#if !COMPILER_SERVICE_AS_DLL
| Some d when not (List.contains d cenv.conditionalDefines) ->
[], false
#endif
| _ ->

// REVIEW: take notice of inherited?
Expand Down
25 changes: 24 additions & 1 deletion tests/service/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,27 @@ module Mod2 =
mod1val1.XmlDocSig |> shouldEqual "P:Mod1.val1"
mod2func2.XmlDocSig |> shouldEqual "M:Mod1.Mod2.func2"



module Attributes =
[<Test>]
let ``Emit conditional attributes`` () =
let source = """
open System
open System.Diagnostics

[<Conditional("Bar")>]
type FooAttribute() =
inherit Attribute()

[<Foo>]
let x = 123
"""
let fileName, options = mkTestFileAndOptions source [| |]
let _, checkResults = parseAndCheckFile fileName source options

checkResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.tryFind (fun su -> su.Symbol.DisplayName = "x")
|> Option.orElseWith (fun _ -> failwith "Could not get symbol")
|> Option.map (fun su -> su.Symbol :?> FSharpMemberOrFunctionOrValue)
|> Option.iter (fun symbol -> symbol.Attributes.Count |> shouldEqual 1)