Skip to content

Commit

Permalink
Merge pull request #45 from pc2/44-objects-that-panic-on-non-empty-dr…
Browse files Browse the repository at this point in the history
…op-should-check-if-the-thread-isnt-panicing-already

Removed double panics from drop
  • Loading branch information
VonTum authored Jan 12, 2025
2 parents aedcac9 + 0c20368 commit 630bd56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;

use std::cell::RefCell;
use std::thread::panicking;

use crate::{alloc::ArenaAllocator, typing::template::TemplateInput};

Expand Down Expand Up @@ -184,7 +185,7 @@ impl<'linker> ErrorCollector<'linker> {

impl<'l> Drop for ErrorCollector<'l> {
fn drop(&mut self) {
if !self.error_store.borrow().is_untouched() {
if !self.error_store.borrow().is_untouched() && !panicking() {
panic!("ErrorCollector should have been emptied!");
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/typing/delayed_constraint.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::thread::panicking;



#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -58,6 +60,8 @@ impl<T> DelayedConstraintsList<T> {

impl<T> Drop for DelayedConstraintsList<T> {
fn drop(&mut self) {
assert_eq!(self.0.len(), 0, "DelayedConstraintsList was not resolved.");
if !panicking() {
assert_eq!(self.0.len(), 0, "DelayedConstraintsList was not resolved.");
}
}
}
5 changes: 4 additions & 1 deletion src/typing/type_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::cell::{OnceCell, RefCell};
use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut, Index};
use std::thread::panicking;

use crate::block_vector::{BlockVec, BlockVecIter};
use crate::errors::ErrorInfo;
Expand Down Expand Up @@ -166,7 +167,9 @@ impl<MyType : HindleyMilner<VariableIDMarker>+Clone, VariableIDMarker : UUIDMark

impl<MyType: HindleyMilner<VariableIDMarker>, VariableIDMarker: UUIDMarker> Drop for TypeSubstitutor<MyType, VariableIDMarker> {
fn drop(&mut self) {
assert!(self.failed_unifications.borrow().is_empty(), "Errors were not extracted before dropping!");
if !panicking() {
assert!(self.failed_unifications.borrow().is_empty(), "Errors were not extracted before dropping!");
}
}
}

Expand Down

0 comments on commit 630bd56

Please sign in to comment.