summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-09-08 21:28:03 -0700
committerOri Bernstein <ori@eigenstate.org>2016-09-08 21:28:03 -0700
commitf536dec7915b6285916c7281ac992c24fa1ccf32 (patch)
tree93af8d91ed0cc5c8dc138145fdbc8dfcd052fee4 /6
parentd5c4a8280725d9430ba07530e5be0f08f29be936 (diff)
downloadmc-f536dec7915b6285916c7281ac992c24fa1ccf32.tar.gz
Allow any type to be cast to its base type.
Diffstat (limited to '6')
-rw-r--r--6/simp.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/6/simp.c b/6/simp.c
index 7d6d9b9..6f5a132 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -543,6 +543,12 @@ static Node *simpcast(Simp *s, Node *val, Type *to)
Type *t;
r = NULL;
+ t = tybase(exprtype(val));
+ if (tyeq(tybase(to), tybase(t))) {
+ r = rval(s, val, NULL);
+ r->expr.type = to;
+ return r;
+ }
/* do the type conversion */
switch (tybase(to)->type) {
case Tybool:
@@ -550,7 +556,6 @@ static Node *simpcast(Simp *s, Node *val, Type *to)
case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
case Tyint: case Tyuint: case Tychar: case Tybyte:
case Typtr:
- t = tybase(exprtype(val));
switch (t->type) {
/* ptr -> slice conversion is disallowed */
case Tyslice:
@@ -590,7 +595,6 @@ static Node *simpcast(Simp *s, Node *val, Type *to)
}
break;
case Tyflt32: case Tyflt64:
- t = tybase(exprtype(val));
switch (t->type) {
case Tyint8: case Tyint16: case Tyint32: case Tyint64:
case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64: