| @@ -578,6 +578,10 @@ impl<'h> Env<'h> { |
| 578 | 578 | let Some(row) = row else { return Ty::RowEmpty }; |
| 579 | 579 | let mut labels: Vec<Ty> = Vec::new(); |
| 580 | 580 | let mut tail = None; |
| 581 | + // A label reported (or already reported, `TypeRef::Error`) and |
| 582 | + // dropped: the row then ends in an error, not closed, so calls |
| 583 | + // performing the missing effect don't each report it (issue #144). |
| 584 | + let mut bad = false; |
| 581 | 585 | for (i, label) in row.labels.iter().enumerate() { |
| 582 | 586 | let is_last = i + 1 == row.labels.len(); |
| 583 | 587 | let span = Span { |
| @@ -585,23 +589,37 @@ impl<'h> Env<'h> { |
| 585 | 589 | range: label.span(), |
| 586 | 590 | }; |
| 587 | 591 | match label { |
| 588 | | − TypeRef::Var { name, .. } if !is_row_var_name(name) => diags.push( |
| 589 | | − Diagnostic::error(codes::NOT_AN_EFFECT, format!("no effect named `{name}` is in scope"), span) |
| 590 | | − .with_note(format!( |
| 591 | | − "import it (e.g. `import std/process.{{type {name}}}`); row variables are named like `e` or `e1`" |
| 592 | | − )), |
| 593 | | − ), |
| 592 | + TypeRef::Var { name, .. } if !is_row_var_name(name) => { |
| 593 | + bad = true; |
| 594 | + diags.push( |
| 595 | + Diagnostic::error(codes::NOT_AN_EFFECT, format!("no effect named `{name}` is in scope"), span) |
| 596 | + .with_note(format!( |
| 597 | + "import it (e.g. `import std/process.{{type {name}}}`); row variables are named like `e` or `e1`" |
| 598 | + )), |
| 599 | + ) |
| 600 | + } |
| 594 | 601 | TypeRef::Var { .. } if is_last && row.tail.is_none() => { |
| 595 | | − tail = Some(self.lower_kinded(label, &Kind::Row, file, scope, ictx.as_deref_mut(), diags)); |
| 602 | + tail = Some(self.lower_kinded( |
| 603 | + label, |
| 604 | + &Kind::Row, |
| 605 | + file, |
| 606 | + scope, |
| 607 | + ictx.as_deref_mut(), |
| 608 | + diags, |
| 609 | + )); |
| 610 | + } |
| 611 | + TypeRef::Var { name, .. } => { |
| 612 | + bad = true; |
| 613 | + diags.push(Diagnostic::error( |
| 614 | + codes::NOT_AN_EFFECT, |
| 615 | + format!("row variable `{name}` must come last in an effect row"), |
| 616 | + span, |
| 617 | + )) |
| 596 | 618 | } |
| 597 | | − TypeRef::Var { name, .. } => diags.push(Diagnostic::error( |
| 598 | | − codes::NOT_AN_EFFECT, |
| 599 | | − format!("row variable `{name}` must come last in an effect row"), |
| 600 | | − span, |
| 601 | | − )), |
| 602 | 619 | TypeRef::Def { def, args, .. } => { |
| 603 | 620 | let data = self.hir.def(*def); |
| 604 | 621 | let DefKind::Effect(effect) = &data.kind else { |
| 622 | + bad = true; |
| 605 | 623 | diags.push(Diagnostic::error( |
| 606 | 624 | codes::NOT_AN_EFFECT, |
| 607 | 625 | format!( |
| @@ -613,6 +631,7 @@ impl<'h> Env<'h> { |
| 613 | 631 | continue; |
| 614 | 632 | }; |
| 615 | 633 | if args.len() != effect.params.len() { |
| 634 | + bad = true; |
| 616 | 635 | diags.push(Diagnostic::error( |
| 617 | 636 | codes::TYPE_ARITY, |
| 618 | 637 | format!( |
| @@ -638,18 +657,22 @@ impl<'h> Env<'h> { |
| 638 | 657 | } |
| 639 | 658 | labels.push(Ty::Con(*def, args)); |
| 640 | 659 | } |
| 641 | | − TypeRef::Error { .. } => {} |
| 642 | | − _ => diags.push(Diagnostic::error( |
| 643 | | − codes::NOT_AN_EFFECT, |
| 644 | | − "expected an effect", |
| 645 | | − span, |
| 646 | | − )), |
| 660 | + TypeRef::Error { .. } => bad = true, |
| 661 | + _ => { |
| 662 | + bad = true; |
| 663 | + diags.push(Diagnostic::error( |
| 664 | + codes::NOT_AN_EFFECT, |
| 665 | + "expected an effect", |
| 666 | + span, |
| 667 | + )) |
| 668 | + } |
| 647 | 669 | } |
| 648 | 670 | } |
| 649 | 671 | if let Some(t) = &row.tail { |
| 650 | 672 | tail = Some(self.lower_kinded(t, &Kind::Row, file, scope, ictx, diags)); |
| 651 | 673 | } |
| 652 | | − Ty::row(labels, tail.unwrap_or(Ty::RowEmpty)) |
| 674 | + let closed = if bad { Ty::Error } else { Ty::RowEmpty }; |
| 675 | + Ty::row(labels, tail.unwrap_or(closed)) |
| 653 | 676 | } |
| 654 | 677 | |
| 655 | 678 | /// The body of `type A<params> = T` with params as `Gen(i)`; `None` if |