Skip to content

[SR-6480] The self value in a class method should always have DynamicSelfType #49030

@hamishknight

Description

@hamishknight
Previous ID SR-6480
Radar rdar://problem/35730964
Original Reporter @hamishknight
Type Bug
Environment

Swift version 4.1-dev (LLVM fe49d8f2ca, Clang 839070845c, Swift 76ea3a2)
Target: x86_64-apple-darwin17.2.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 2df450011114c0bdf1e6f6a7bba3ac45

is duplicated by:

  • SR-14899 self is not convertible to Self type

Issue Description:

The following code outputs "C":

class C {
  static var foo: String { return "\(self)" }
  let bar = foo
}

class D : C {}

print(D().bar) // C

Despite the fact that it's a D instance being constructed.

This also prevents overrides of class members from working:

class C {
  class var foo: String { return "C" }
  let bar = foo
}

class D : C {
  override class var foo: String { return "D" }
}

print(D().bar) // C

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions