mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Disallow typing optional fields when required fields are annotated
Closes #4313
This commit is contained in:
parent
62c9a2a8b6
commit
05e8e6de6f
13 changed files with 133 additions and 85 deletions
|
@ -1845,6 +1845,7 @@ fn unify_shared_fields<M: MetaCollector>(
|
|||
//
|
||||
// Demanded does not unify with Optional
|
||||
// RigidOptional does not unify with Required or Demanded
|
||||
// RigidRequired does not unify with Optional
|
||||
// Unifying Required with Demanded => Demanded
|
||||
// Unifying Optional with Required => Required
|
||||
// Unifying Optional with RigidOptional => RigidOptional
|
||||
|
@ -1861,15 +1862,26 @@ fn unify_shared_fields<M: MetaCollector>(
|
|||
(Required(val), Optional(_)) => Required(val),
|
||||
(Optional(val), Required(_)) => Required(val),
|
||||
(Optional(val), Optional(_)) => Optional(val),
|
||||
|
||||
// rigid optional
|
||||
(RigidOptional(val), Optional(_)) | (Optional(_), RigidOptional(val)) => {
|
||||
RigidOptional(val)
|
||||
}
|
||||
(RigidOptional(_), Demanded(_) | Required(_))
|
||||
| (Demanded(_) | Required(_), RigidOptional(_)) => {
|
||||
(RigidOptional(_), Demanded(_) | Required(_) | RigidRequired(_))
|
||||
| (Demanded(_) | Required(_) | RigidRequired(_), RigidOptional(_)) => {
|
||||
// this is an error, but we continue to give better error messages
|
||||
continue;
|
||||
}
|
||||
(RigidOptional(val), RigidOptional(_)) => RigidOptional(val),
|
||||
|
||||
// rigid required
|
||||
(RigidRequired(_), Optional(_)) | (Optional(_), RigidRequired(_)) => {
|
||||
// this is an error, but we continue to give better error messages
|
||||
continue;
|
||||
}
|
||||
(RigidRequired(val), Demanded(_) | Required(_))
|
||||
| (Demanded(_) | Required(_), RigidRequired(val)) => RigidRequired(val),
|
||||
(RigidRequired(val), RigidRequired(_)) => RigidRequired(val),
|
||||
};
|
||||
|
||||
matching_fields.push((name, actual));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue