Files
swift-mirror/test/Sema/swiftsettings_duplicates.swift
Michael Gottesman 4b31382d67 [swift-settings] Only allow for a setting to be passed exactly once to #SwiftSettings.
This responds to some feedback on the forums. Most importantly this allows for
us to use variadic generics in the the type system to document whether we allow
for "appending" behavior or not. Previously, for some options we would take the
last behavior (and theoretically) for others would have silently had appending
behavior. This just makes the behavior simple and more explicit.
2025-03-17 14:03:52 -07:00

25 lines
1.4 KiB
Swift

// RUN: %target-swift-frontend -enable-experimental-feature SwiftSettings -enable-experimental-feature Macros -c -swift-version 6 -disable-availability-checking -verify %s
// REQUIRES: asserts
// REQUIRES: concurrency
// REQUIRES: swift_feature_Macros
// REQUIRES: swift_feature_SwiftSettings
// This test specifically tests the behavior of #SwiftSettings when we find
// multiple instances of the same setting.
actor MyActor {}
#SwiftSettings(.defaultIsolation(MainActor.self), // expected-note 6 {{setting originally passed here}}
.defaultIsolation(nil)) // expected-error {{duplicate setting passed to #SwiftSettings}}
#SwiftSettings(.defaultIsolation(nil)) // expected-error {{duplicate setting passed to #SwiftSettings}}
#SwiftSettings(.defaultIsolation(MyActor.self)) // expected-error {{duplicate setting passed to #SwiftSettings}}
#SwiftSettings(.defaultIsolation(1)) // expected-error {{duplicate setting passed to #SwiftSettings}}
// expected-error @-1 {{cannot convert value of type 'Int' to expected argument type 'any Actor.Type'}}
#SwiftSettings(2) // expected-error {{Unrecognized setting passed to #SwiftSettings}}
// expected-error @-1 {{cannot convert value of type 'Int' to expected argument type 'SwiftSetting'}}
#SwiftSettings(.defaultIsolation(MainActor.self), // expected-error {{duplicate setting passed to #SwiftSettings}}
.defaultIsolation(nil)) // expected-error {{duplicate setting passed to #SwiftSettings}}