Skip to content

No diagnostics is produced for non-default traits #2355

@MaxDesiatov

Description

@MaxDesiatov

Swift version

swift-DEVELOPMENT-SNAPSHOT-2025-11-03-a, also reproducible with Xcode 26.0.1.

Platform

macOS 15.7.2

Editor

Neovim

Description

No diagnostics is produced within code-blocks hidden in non-default traits even if such traits are enabled in .sourcekit-lsp/config.json. Code in such blocks is also not indexed.

Steps to Reproduce

mkdir traits-repro
cd traits-repro
swift package init

Make sure that Package.swift looks like this:

// swift-tools-version: 6.2

import PackageDescription

let package = Package(
    name: "traits-repro",
    products: [
        .library(
            name: "traits-repro",
            targets: ["traits-repro"]
        ),
    ],
    traits: [
        .default(enabledTraits: []),
        "NonDefaultTrait",
    ],
    targets: [
        .target(
            name: "traits-repro"
        ),
    ]
)

Enable the trait in .sourcekit-lsp/config.json:

{
    "swiftPM": {
        "traits": ["NonDefaultTrait"]
    }
}

Add following code to Sources/traits-repro/traits_repro.swift:

#if NonDefaultTrait

func f(arg: Int) {
    arg
}

func g() {
    f(arg: "foo")
}

#endif

You will see that no error diagnostic is produced in the body of func g() declaration as long as NonDefaultTrait is not included in the default trait.

Logging

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions