[SR-6895] Timer property with initializer and self
target causes crash at runtime
#49444
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
duplicate
Resolution: Duplicates another issue
expressions
Feature: expressions
identifiers
Feature: Identifiers
missing warning
Bug: Missing warning
self
Feature → expressions: The 'self' expression
swift 5.6
type checker
Area → compiler: Semantic analysis
Environment
Swift 4.1, Xcode 9.3 beta 1
Additional Detail from JIRA
md5: b788bbb198c95ec64db19b32b0652bd1
duplicates:
Issue Description:
I thought I had raised this issue before, but now I see that I never made it explicit, so I'd like this code on the record:
That code is legal (the compiler doesn't complain) but causes a crash at runtime. The reason seems to be that the
self
referred to as the target is not the view controller (presumably because our object is not fully formed the time we are initializing properties).This is a very common trap for beginners to fall into. The compiler should disallow this use of
self
.This may be a duplicate of #47442 but I was not so explicit there about the
Timer
problem, which is the common use case that bites everyone.The text was updated successfully, but these errors were encountered: