fix: found issue with record access on Pairs
This commit is contained in:
parent
cb1ca84dad
commit
7b5ad961e2
|
@ -5,8 +5,8 @@ use crate::{
|
||||||
},
|
},
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
tipo::{
|
tipo::{
|
||||||
fields::FieldMap, Type, TypeAliasAnnotation, TypeConstructor, TypeInfo, TypeVar,
|
fields::FieldMap, AccessorsMap, RecordAccessor, Type, TypeAliasAnnotation, TypeConstructor,
|
||||||
ValueConstructor, ValueConstructorVariant,
|
TypeInfo, TypeVar, ValueConstructor, ValueConstructorVariant,
|
||||||
},
|
},
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
};
|
};
|
||||||
|
@ -347,7 +347,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
||||||
ValueConstructor::public(
|
ValueConstructor::public(
|
||||||
function(
|
function(
|
||||||
vec![fst_parameter.clone(), snd_parameter.clone()],
|
vec![fst_parameter.clone(), snd_parameter.clone()],
|
||||||
pair(fst_parameter, snd_parameter),
|
pair(fst_parameter.clone(), snd_parameter.clone()),
|
||||||
),
|
),
|
||||||
ValueConstructorVariant::Record {
|
ValueConstructorVariant::Record {
|
||||||
module: "".into(),
|
module: "".into(),
|
||||||
|
@ -364,6 +364,34 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut accessors = HashMap::new();
|
||||||
|
accessors.insert(
|
||||||
|
"fst".to_string(),
|
||||||
|
RecordAccessor {
|
||||||
|
index: 0,
|
||||||
|
label: "fst".to_string(),
|
||||||
|
tipo: fst_parameter.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
accessors.insert(
|
||||||
|
"snd".to_string(),
|
||||||
|
RecordAccessor {
|
||||||
|
index: 1,
|
||||||
|
label: "snd".to_string(),
|
||||||
|
tipo: snd_parameter.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
prelude.accessors.insert(
|
||||||
|
PAIR.to_string(),
|
||||||
|
AccessorsMap {
|
||||||
|
public: true,
|
||||||
|
tipo: pair(fst_parameter.clone(), snd_parameter.clone()),
|
||||||
|
accessors,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// String
|
// String
|
||||||
prelude.types.insert(
|
prelude.types.insert(
|
||||||
STRING.to_string(),
|
STRING.to_string(),
|
||||||
|
@ -702,7 +730,7 @@ pub fn from_default_function(builtin: DefaultFunction, id_gen: &IdGenerator) ->
|
||||||
(tipo, 2)
|
(tipo, 2)
|
||||||
}
|
}
|
||||||
DefaultFunction::MapData => {
|
DefaultFunction::MapData => {
|
||||||
let tipo = function(vec![list(tuple(vec![data(), data()]))], data());
|
let tipo = function(vec![list(pair(data(), data()))], data());
|
||||||
|
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
|
@ -722,12 +750,12 @@ pub fn from_default_function(builtin: DefaultFunction, id_gen: &IdGenerator) ->
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
DefaultFunction::UnConstrData => {
|
DefaultFunction::UnConstrData => {
|
||||||
let tipo = function(vec![data()], tuple(vec![int(), list(data())]));
|
let tipo = function(vec![data()], pair(int(), list(data())));
|
||||||
|
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
DefaultFunction::UnMapData => {
|
DefaultFunction::UnMapData => {
|
||||||
let tipo = function(vec![data()], list(tuple(vec![data(), data()])));
|
let tipo = function(vec![data()], list(pair(data(), data())));
|
||||||
|
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
|
@ -772,7 +800,7 @@ pub fn from_default_function(builtin: DefaultFunction, id_gen: &IdGenerator) ->
|
||||||
(tipo, 6)
|
(tipo, 6)
|
||||||
}
|
}
|
||||||
DefaultFunction::MkPairData => {
|
DefaultFunction::MkPairData => {
|
||||||
let tipo = function(vec![data(), data()], tuple(vec![data(), data()]));
|
let tipo = function(vec![data(), data()], pair(data(), data()));
|
||||||
(tipo, 2)
|
(tipo, 2)
|
||||||
}
|
}
|
||||||
DefaultFunction::MkNilData => {
|
DefaultFunction::MkNilData => {
|
||||||
|
@ -780,7 +808,7 @@ pub fn from_default_function(builtin: DefaultFunction, id_gen: &IdGenerator) ->
|
||||||
(tipo, 0)
|
(tipo, 0)
|
||||||
}
|
}
|
||||||
DefaultFunction::MkNilPairData => {
|
DefaultFunction::MkNilPairData => {
|
||||||
let tipo = function(vec![], list(tuple(vec![data(), data()])));
|
let tipo = function(vec![], list(pair(data(), data())));
|
||||||
(tipo, 0)
|
(tipo, 0)
|
||||||
}
|
}
|
||||||
DefaultFunction::ChooseUnit => {
|
DefaultFunction::ChooseUnit => {
|
||||||
|
@ -796,13 +824,13 @@ pub fn from_default_function(builtin: DefaultFunction, id_gen: &IdGenerator) ->
|
||||||
DefaultFunction::FstPair => {
|
DefaultFunction::FstPair => {
|
||||||
let a = generic_var(id_gen.next());
|
let a = generic_var(id_gen.next());
|
||||||
let b = generic_var(id_gen.next());
|
let b = generic_var(id_gen.next());
|
||||||
let tipo = function(vec![tuple(vec![a.clone(), b])], a);
|
let tipo = function(vec![pair(a.clone(), b)], a);
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
DefaultFunction::SndPair => {
|
DefaultFunction::SndPair => {
|
||||||
let a = generic_var(id_gen.next());
|
let a = generic_var(id_gen.next());
|
||||||
let b = generic_var(id_gen.next());
|
let b = generic_var(id_gen.next());
|
||||||
let tipo = function(vec![tuple(vec![a, b.clone()])], b);
|
let tipo = function(vec![pair(a, b.clone())], b);
|
||||||
(tipo, 1)
|
(tipo, 1)
|
||||||
}
|
}
|
||||||
DefaultFunction::ChooseList => {
|
DefaultFunction::ChooseList => {
|
||||||
|
|
|
@ -837,7 +837,11 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
.get(module)
|
.get(module)
|
||||||
.and_then(|module| module.accessors.get(name)),
|
.and_then(|module| module.accessors.get(name)),
|
||||||
|
|
||||||
_something_without_fields => return Err(unknown_field(vec![])),
|
Type::Pair { .. } => self.environment.accessors.get("Pair"),
|
||||||
|
|
||||||
|
_something_without_fields => {
|
||||||
|
return Err(unknown_field(vec![]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.ok_or_else(|| unknown_field(vec![]))?;
|
.ok_or_else(|| unknown_field(vec![]))?;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ type Foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_constr(data: Data) -> Int {
|
fn get_constr(data: Data) -> Int {
|
||||||
builtin.un_constr_data(data).1st
|
builtin.un_constr_data(data).fst
|
||||||
}
|
}
|
||||||
|
|
||||||
test foo() {
|
test foo() {
|
||||||
|
@ -23,7 +23,7 @@ fn map(list: List<a>, f: fn(a) -> b) -> List<b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fields(data: Data) -> List<Int> {
|
fn get_fields(data: Data) -> List<Int> {
|
||||||
builtin.un_constr_data(data).2nd
|
builtin.un_constr_data(data).snd
|
||||||
|> map(builtin.un_i_data)
|
|> map(builtin.un_i_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue