Record accessors
The record accessor syntax record.field_label
can be used to get
contained values from a custom type record.
The accessor syntax can only be used for fields with the same name that are in the same position and have the same type for all variants of the custom type.
The name
field is in the first position and has type
String
for all variants, so it can be accessed.
The subject
field is absent on the Student
variant,
so it cannot be used on any variant of type SchoolPerson
.
Uncomment the teacher.subject
line to see the compile error from
trying to use this accessor.