shithub: mc

Download patch

ref: f536dec7915b6285916c7281ac992c24fa1ccf32
parent: d5c4a8280725d9430ba07530e5be0f08f29be936
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 8 17:28:03 EDT 2016

Allow any type to be cast to its base type.

--- a/6/simp.c
+++ b/6/simp.c
@@ -543,6 +543,12 @@
 	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 @@
 	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 @@
 		}
 		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: