From 0887760de10bfa7831dc264831b20d030f8ccb61 Mon Sep 17 00:00:00 2001 From: Aaron Gutierrez Date: Sat, 29 Apr 2017 15:56:43 -0400 Subject: [PATCH] [WIP] typechecking for casts to polymorphic types --- expr.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/expr.cpp b/expr.cpp index 99648f91..51e7dd56 100644 --- a/expr.cpp +++ b/expr.cpp @@ -276,6 +276,8 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, const AtomicType *fromAtomicType = CastType(fromType); const PointerType *fromPointerType = CastType(fromType); const PointerType *toPointerType = CastType(toType); + const PolyType *fromPolyType = CastType(fromType); + const PolyType *toPolyType = CastType(toType); // Do this early, since for the case of a conversion like // "float foo[10]" -> "float * uniform foo", we have what's seemingly @@ -544,6 +546,20 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, goto typecast_ok; } + // atomic -> polymorphic + if ((fromAtomicType || fromPolyType) && toPolyType) { + if (toPolyType->CanBeType(fromType)) { + goto typecast_ok; + } else { + if (!failureOk) { + Error(pos, "Can't convert between \"%s\" and polymorphic type " + "\"%s\" for %s", fromType->GetString().c_str(), + toPolyType->GetString().c_str(), errorMsgBase); + } + } + } + + // from here on out, the from type can only be atomic something or // other... if (fromAtomicType == NULL) {