From b4f86c449fa3375776b74d27ff24afbf86c2afb5 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 3 Mar 2021 21:34:10 +0100 Subject: [PATCH] try harder to find a list element type --- compiler/mono/src/ir.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index dc904a50cd..b174ae70c4 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1,8 +1,8 @@ use self::InProgressProc::*; use crate::exhaustive::{Ctor, Guard, RenderAs, TagId}; use crate::layout::{ - BuildClosureData, Builtin, ClosureLayout, Layout, LayoutCache, LayoutProblem, UnionLayout, - WrappedVariant, TAG_SIZE, + BuildClosureData, Builtin, ClosureLayout, Layout, LayoutCache, LayoutProblem, MemoryMode, + UnionLayout, WrappedVariant, TAG_SIZE, }; use bumpalo::collections::Vec; use bumpalo::Bump; @@ -3357,10 +3357,33 @@ pub fn with_hole<'a>( } } - List { loc_elems, .. } if loc_elems.is_empty() => { + List { + loc_elems, + elem_var, + .. + } if loc_elems.is_empty() => { // because an empty list has an unknown element type, it is handled differently - let expr = Expr::EmptyArray; - Stmt::Let(assigned, expr, Layout::Builtin(Builtin::EmptyList), hole) + let opt_elem_layout = layout_cache.from_var(env.arena, elem_var, env.subs); + + match opt_elem_layout { + Ok(elem_layout) => { + let expr = Expr::EmptyArray; + Stmt::Let( + assigned, + expr, + Layout::Builtin(Builtin::List( + MemoryMode::Refcounted, + env.arena.alloc(elem_layout), + )), + hole, + ) + } + Err(LayoutProblem::UnresolvedTypeVar(_)) => { + let expr = Expr::EmptyArray; + Stmt::Let(assigned, expr, Layout::Builtin(Builtin::EmptyList), hole) + } + Err(LayoutProblem::Erroneous) => panic!("list element is error type"), + } } List {