Skip to content

Commit 0477978

Browse files
committed
Add type checking on builtins as a call arg
This is a runtime error currently but can be pushed back to a compiler error with some work
1 parent effe519 commit 0477978

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

spec/invalid/not_id.expr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(not id)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VERSION 0700
2+
----
3+
0000 GET BUILTIN 16 == 'not'
4+
0003 GET BUILTIN 0 == 'id'
5+
0006 CALL (1 args)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
(
3+
RuntimeError(
4+
TypeMismatch {
5+
expected: Bool,
6+
actual: Fn(Value) -> Value,
7+
},
8+
),
9+
0..0,
10+
),
11+
]

src/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ impl Value {
4242
RuntimeError::TypeMismatch {
4343
expected: Type::Fn {
4444
args: vec![],
45-
variadic_arg: Some(Type::Unknown.into()),
46-
returns: Type::Unknown.into(),
45+
variadic_arg: Some(Type::Value.into()),
46+
returns: Type::Value.into(),
4747
},
4848
actual: self.get_type(),
4949
}
@@ -140,8 +140,8 @@ mod tests {
140140
RuntimeError::TypeMismatch {
141141
expected: Type::Fn {
142142
args: vec![],
143-
variadic_arg: Some(Type::Unknown.into()),
144-
returns: Type::Unknown.into()
143+
variadic_arg: Some(Type::Value.into()),
144+
returns: Type::Value.into()
145145
},
146146
actual: Type::String
147147
}
@@ -174,8 +174,8 @@ mod tests {
174174
RuntimeError::TypeMismatch {
175175
expected: Type::Fn {
176176
args: vec![],
177-
variadic_arg: Some(Type::Unknown.into()),
178-
returns: Type::Unknown.into()
177+
variadic_arg: Some(Type::Value.into()),
178+
returns: Type::Value.into()
179179
},
180180
actual: Type::Bool
181181
}

0 commit comments

Comments
 (0)