Skip to content

Commit

Permalink
fix: refinement type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 14, 2024
1 parent 60f0388 commit 9774a62
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/erg_compiler/context/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,8 @@ impl Context {
lhs: TyParam,
rhs: TyParam,
) -> EvalResult<TyParam> {
let lhs = self.eval_tp(lhs).map_err(|(_, es)| es)?;
let rhs = self.eval_tp(rhs).map_err(|(_, es)| es)?;
// let lhs = self.eval_tp(lhs).map_err(|(_, es)| es)?;
// let rhs = self.eval_tp(rhs).map_err(|(_, es)| es)?;
match (lhs, rhs) {
(TyParam::Value(lhs), TyParam::Value(rhs)) => {
self.eval_bin(op, lhs, rhs).map(TyParam::value)
Expand Down Expand Up @@ -1807,7 +1807,7 @@ impl Context {

/// val: may be unevaluated
pub(crate) fn eval_unary_tp(&self, op: OpKind, val: TyParam) -> EvalResult<TyParam> {
let val = self.eval_tp(val).map_err(|(_, es)| es)?;
// let val = self.eval_tp(val).map_err(|(_, es)| es)?;
match val {
TyParam::Value(c) => self.eval_unary_val(op, c).map(TyParam::Value),
TyParam::FreeVar(fv) if fv.is_linked() => {
Expand All @@ -1824,9 +1824,9 @@ impl Context {

/// args: may be unevaluated
pub(crate) fn eval_app(&self, name: Str, args: Vec<TyParam>) -> Failable<TyParam> {
let args = self
.eval_type_args(args)
.map_err(|(args, es)| (TyParam::app(name.clone(), args), es))?;
/*let args = self
.eval_type_args(args)
.map_err(|(args, es)| (TyParam::app(name.clone(), args), es))?;*/
if let Ok(value_args) = args
.iter()
.map(|tp| self.convert_tp_into_value(tp.clone()))
Expand Down
13 changes: 13 additions & 0 deletions tests/should_ok/dependent_refinement.er
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ndarray = pyimport "ndarray"

a as ndarray.NDArray(Int, [2, 3]) = todo()

check|T, Shape: {A: [Nat; _] | all(map((X -> X > 1), A))}|(
_: ndarray.NDArray(T, Shape)
) = None
check a

check2|T, Shape: [Nat; _]|(
_: {_: ndarray.NDArray(T, Shape) | all(map((X -> X > 1), Shape))}
) = None
check2 a
3 changes: 3 additions & 0 deletions tests/should_ok/ndarray.d.er
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.NDArray: (T: Type, Shape: [Nat; _]) -> ClassType
.NDArray(T, _) <: Output T
.NDArray(_, _) <: Num
5 changes: 5 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ fn exec_dependent() -> Result<(), ()> {
expect_success("tests/should_ok/dependent.er", 0)
}

#[test]
fn exec_dependent_refinement() -> Result<(), ()> {
expect_compile_success("tests/should_ok/dependent_refinement.er", 0)
}

#[test]
fn exec_dict() -> Result<(), ()> {
expect_success("examples/dict.er", 0)
Expand Down

0 comments on commit 9774a62

Please sign in to comment.