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
@jamieQ
Copy link
Contributor

jamieQ commented Dec 7, 2025

@swift-ci please smoke test

@jamieQ
Copy link
Contributor

jamieQ commented Dec 8, 2025

@swift-ci please smoke test linux

@jamieQ
Copy link
Contributor

jamieQ commented Dec 15, 2025

@eeckstein could you review/merge when you have a chance please?

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@eeckstein eeckstein merged commit f092709 into swiftlang:main Dec 15, 2025
3 checks passed
@aeu aeu deleted the ast_suppress_compiler_warning branch December 15, 2025 17:03
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.

3 participants