Skip to content

Sema: Fix opaque type accessors with inactive availability conditions #77519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

tshortli
Copy link
Contributor

Opaque type metadata accessor functions could be miscompiled for functions that contain if #available checks for inactive platforms. For example, this function will always return A when compiled for macOS, but the opaque type accessor would instead return the type metadata for B:

func f() -> some P {
  if #available(iOS 99, *) {
    return A() // Returns an A on macOS
  } else {
    return B()
  }
}

Resolves rdar://139487970.

It doesn't make sense to use `VersionRange::empty()` to represent "universally
available" since something that is available in an empty version range is
effectively never available.
Opaque type metadata accessor functions could be miscompiled for functions that
contain `if #available` checks for inactive platforms. For example, this
function will always return `A` when compiled for macOS, but the opaque type
accessor would instead return the type metadata for `B`:

```
func f() -> some P {
  if #available(iOS 99, *) {
    return A() // Returns an A on macOS
  } else {
    return B()
  }
}
```

Resolves rdar://139487970.
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli merged commit 600ed07 into swiftlang:main Nov 11, 2024
5 checks passed
@tshortli tshortli deleted the fix-conditional-opaque-type-miscompile branch November 11, 2024 17:22
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.

2 participants