Skip to content

FlagResolution.getTyped casts self instead of value #252

Description

@nicklasl

In Sources/Confidence/FlagEvaluation.swift, the first check in getTyped casts the FlagResolution struct itself rather than the ConfidenceValue parameter:

https://github.com/spotify/confidence-sdk-swift/blob/main/Sources/Confidence/FlagEvaluation.swift#L228

private func getTyped<T>(value: ConfidenceValue, defaultValue: T) throws -> T? {
    if let value = self as? T {   // `self` is the FlagResolution, not the value
        return value
    }
    ...

Since self is a FlagResolution, this cast can never succeed for any supported flag type, so the check silently falls through to the switch below. It looks like the intent was if let value = value as? T (return early when the resolved value is already of the requested type).

Harmless today as far as I can tell, but it's dead code that hides the intended fast path — worth a one-line fix (or removal) plus a test.

Found while auditing the evaluation path during a crash investigation (no relation to the crash itself).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions