Skip to content

Conversation

@aeu
Copy link
Contributor

@aeu aeu commented Dec 6, 2025

Issue

Warning when building the compiler

[1429/1722][ 82%][5851.879s] Building swift module AST
/mnt/storage/work/swift-project/swift/SwiftCompilerSources/Sources/AST/Declarations.swift:29:19: warning: treating a forced downcast to 'any DeclContext' as optional will nev
er produce 'nil'
 27 |   final public var parentDeclContext: DeclContext? {
 28 |     if let decl = bridged.getParent().decl {
 29 |       return decl as! DeclContext
    |              |    | `- note: use 'as?' to perform a conditional downcast to 'any DeclContext'
    |              |    `- warning: treating a forced downcast to 'any DeclContext' as optional will never produce 'nil'
    |              `- note: add parentheses around the cast to silence this warning
 30 |     }
 31 |     if let bridgedDeclContext = BridgedDeclContext(bridged: bridged.getDeclContext()) {

The compiler emits a diagnostic in parentDeclContext indicating that a forced cast is being treated as if it could produce nil. This occurs because the return type is DeclContext? and the ungrouped as! expression causes the warning.

Changes

Added parens to suppress the warning as recommended by the diagnostic.

@aeu aeu requested a review from eeckstein as a code owner December 6, 2025 16:38
@aeu aeu changed the title suppress AST compiler warning [AST] suppress compiler warning Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant