diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-22 18:48:07 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-22 18:48:07 +0800 |
commit | ffd0a5d215bfc74eb3657bc3feee321337243183 (patch) | |
tree | 90c34312ceba76cc5b55a0a854fb9a4d641092fd | |
parent | 1e1c20bea9987639ee1ca7e76965bbaa42eadc84 (diff) | |
download | mrust-ffd0a5d215bfc74eb3657bc3feee321337243183.tar.gz |
HIR Typecheck Expressions - Avoid inferring literal ivars to non-literals
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 8e15e1ab..f430c7d2 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -5202,6 +5202,41 @@ namespace { } }; + // If this type has an infer class active, don't allw a non-primitive to coerce over it. + switch( ty_l.m_data.as_Infer().ty_class ) + { + case ::HIR::InferClass::Integer: + case ::HIR::InferClass::Float: + // TODO: Actively search possibility list for the real type. + for(const auto& ty : ivar_ent.types_coerce_to) + if( ty.m_data.is_Primitive() ) { + context.equate_types(sp, ty_l, ty); + ivar_ent = Context::IVarPossible(); + return ; + } + for(const auto& ty : ivar_ent.types_unsize_to) + if( ty.m_data.is_Primitive() ) { + context.equate_types(sp, ty_l, ty); + ivar_ent = Context::IVarPossible(); + return ; + } + for(const auto& ty : ivar_ent.types_coerce_from) + if( ty.m_data.is_Primitive() ) { + context.equate_types(sp, ty_l, ty); + ivar_ent = Context::IVarPossible(); + return ; + } + for(const auto& ty : ivar_ent.types_unsize_from) + if( ty.m_data.is_Primitive() ) { + context.equate_types(sp, ty_l, ty); + ivar_ent = Context::IVarPossible(); + return ; + } + ivar_ent = Context::IVarPossible(); + return ; + default: + break; + } if( ivar_ent.force_no_to == true || ivar_ent.force_no_from ) { |