summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/simp.c10
-rw-r--r--test/fncast.myr16
-rw-r--r--test/tests1
3 files changed, 24 insertions, 3 deletions
diff --git a/6/simp.c b/6/simp.c
index d4dd168..c6db9b7 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -933,11 +933,15 @@ static Node *simpcast(Simp *s, Node *val, Type *to)
switch (t->type) {
/* ptr -> slice conversion is disallowed */
case Tyslice:
- if (t->type == Typtr)
- fatal(val, "bad cast from %s to %s",
- tystr(exprtype(val)), tystr(to));
+ if (to->type != Typtr)
+ fatal(val, "bad cast from %s to %s", tystr(exprtype(val)), tystr(to));
r = slicebase(s, val, NULL);
break;
+ case Tyfunc:
+ if (to->type != Typtr)
+ fatal(val, "bad cast from %s to %s", tystr(exprtype(val)), tystr(to));
+ r = getcode(s, val);
+ break;
/* signed conversions */
case Tyint8: case Tyint16: case Tyint32: case Tyint64:
case Tyint:
diff --git a/test/fncast.myr b/test/fncast.myr
new file mode 100644
index 0000000..08b8d1e
--- /dev/null
+++ b/test/fncast.myr
@@ -0,0 +1,16 @@
+use std
+
+const main = {
+ var fn, envfn
+ var ptr
+
+ fn = {
+ }
+ envfn = {
+ ptr = ptr
+ }
+ ptr = fn castto(byte#)
+ ptr = envfn castto(byte#)
+ std.put("ok\n", ptr)
+}
+
diff --git a/test/tests b/test/tests
index e24a6c5..9fb9246 100644
--- a/test/tests
+++ b/test/tests
@@ -59,6 +59,7 @@ B callbig E 42
B nestfn E 42
B foldidx P 123,456
B closure P 111555333666
+B fncast P ok
B loop P 0123401236789
B subrangefor P 12
B patiter P 23512