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
[SR-1327] Ignored expressions should be correctly evaluated if they have side effects #43935
Comments
Comment by Jacob G (JIRA) It also seems to only happen when using |
Comment by Haris Amin (JIRA) Can we close/resolve this issue? Running the attached `main.swift` now on 3.0.1 and 3.0.2 properly throws exception. main.swift:11:20: error: '.dynamicType' is deprecated. Use 'type(of: ...)' instead |
Comment by John Regner (JIRA) The result you are seeing harisamin (JIRA User) is because I think the question here is "What is the expected behavior?". In the sample code above the code intends to check/print the runtime type of a property on a struct. In my opinion, the behavior you are seeing is the correct behavior. I've found the implementation in Looks like this is resolved by the "type checker", I'm guessing that there is no effort to "unwrap" the value that would result in the "Unexpectedly found nil" that you are expecting. /// - Parameter value: The value to find the dynamic type of.
/// - Returns: The dynamic type, which is a value of metatype type.
@_transparent
@_semantics("typechecker.type(of:)")
public func type<T, Metatype>(of value: T) -> Metatype {
// This implementation is never used, since calls to `Swift.type(of:)` are
// resolved as a special case by the type checker.
Builtin.staticReport(_trueAfterDiagnostics(), true._value,
("internal consistency error: 'type(of:)' operation failed to resolve"
as StaticString).utf8Start._rawValue)
Builtin.unreachable()
} Suggest to close, works as expected. |
john_regner (JIRA User) Although calls to |
The first example has actually already been fixed (accidentally, I think) by #14299, as when coercing the lvalue to an rvalue for the call argument to Though it seems a shame a load has to actually be performed here, rather than just getting the address, which is what I believe could've happened if the force unwrap component was a part of the lvalue and we fixed the side effect logic. The side effect logic still needs fixing in the general case though. |
Environment
Apple Swift version 4.1 (swiftlang-902.0.34 clang-902.0.30)
Target: x86_64-apple-darwin17.3.0
Additional Detail from JIRA
md5: b94cb22caf1bfd698f623f19cbd8f12c
Issue Description:
The following examples should all crash at runtime, but don't:
The problem is that currently with expressions like
type(of:)
, the subexpression can be emitted as an "ignored expression" (SILGenExr.cpp,SILGenFunction::emitIgnoredExpr
), meaning that for loads, we try not to actually perform the load it if we can avoid it (if loading won't have side-effects, that is).However, currently we base the side-effects of an lvalue load off whether the components are physical or not. This is incorrect as physical components such as force unwrapping and key-paths can have side effects.
The text was updated successfully, but these errors were encountered: