Skip to content

Instantly share code, notes, and snippets.

@es-kumagai
Created January 17, 2023 13:37
Show Gist options
  • Save es-kumagai/3390f033243d93a86e91d2e37f0a89e0 to your computer and use it in GitHub Desktop.
Save es-kumagai/3390f033243d93a86e91d2e37f0a89e0 to your computer and use it in GitHub Desktop.
先ほどのコードに、インスタンスが具体的にどう扱われているかを窺うコードを追加。内部的な扱いは同じ様子でも、型注釈を明記すると自己準拠性の扱いが変わってくるみたい。 #CodePiece
something(a) // "some A"
something(b) // "some A"
something(c) // "some A"
something(a as A) // "Any"
something(b as A) // "Any"
something(c as A) // "Any"
MemoryLayout.size(ofValue: a) // 8
MemoryLayout.size(ofValue: b) // 40
MemoryLayout.size(ofValue: c) // 40
MemoryLayout.size(ofValue: a as A) // 40
MemoryLayout.size(ofValue: b as A) // 40
MemoryLayout.size(ofValue: c as A) // 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment