1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-06 16:18:08 +03:00

Change back the Ident.pos field to public attribute and remove access method

This commit is contained in:
Anthony Caccia 2022-10-03 13:28:42 +02:00
parent c8bec539d2
commit 4a023fde70
6 changed files with 11 additions and 15 deletions

View File

@ -121,7 +121,7 @@ impl Match {
// - missing field on the `id`
Match::Assign(id, m, (_, d @ Destruct::Record { .. })) => {
let label @ Label { span, .. } = d.label();
let span = RawSpan::fuse(id.pos().unwrap(), span).unwrap();
let span = RawSpan::fuse(id.pos.unwrap(), span).unwrap();
let label = Label { span, ..label };
(
id,

View File

@ -475,7 +475,7 @@ fn cross_apply_contracts<'a>(
let ty_closure = ctr.types.clone().closurize(&mut env1_local, env2.clone());
mk_term::assume(ty_closure, ctr.label.clone(), acc)
.map_err(|crate::types::UnboundTypeVariableError(id)| {
let pos = id.pos();
let pos = id.pos;
EvalError::UnboundIdentifier(id, pos)
})
.map(|rt| rt.with_pos(pos))

View File

@ -12,7 +12,7 @@ static INTERNER: Lazy<interner::Interner> = Lazy::new(interner::Interner::new);
#[serde(into = "String", from = "String")]
pub struct Ident {
symbol: interner::Symbol,
pos: TermPos,
pub pos: TermPos,
generated: bool,
}
@ -33,10 +33,6 @@ impl Ident {
pub fn label(&self) -> &str {
INTERNER.lookup(self.symbol)
}
pub fn pos(&self) -> TermPos {
self.pos
}
}
/// Special character used for generating fresh identifiers. It must be syntactically impossible to

View File

@ -400,7 +400,7 @@ Match: Match = {
_ => MetaValue {
contracts: vec![Contract{
types: Types(AbsType::Dyn().into()),
label: Label{span: left.pos().unwrap(), ..Default::default()},
label: Label{span: left.pos.unwrap(), ..Default::default()},
}],
..Default::default()
},
@ -415,7 +415,7 @@ Match: Match = {
_ => MetaValue {
contracts: vec![Contract{
types: Types(AbsType::Dyn().into()),
label: Label{span: id.pos().unwrap(), ..Default::default()},
label: Label{span: id.pos.unwrap(), ..Default::default()},
}],
..Default::default()
},

View File

@ -91,7 +91,7 @@ impl TryFrom<UniTerm> for RichTerm {
UniTermNode::Types(ty) => {
ty.contract().map_err(|UnboundTypeVariableError(id)| {
// We unwrap the position of the identifier, which must be set at this stage of parsing
let pos = id.pos();
let pos = id.pos;
ParseError::UnboundTypeVariables(vec![id], pos.unwrap())
})?
}
@ -187,7 +187,7 @@ impl UniRecord {
let span = path
.into_iter()
.map(|path_elem| match path_elem {
FieldPathElem::Ident(id) => id.pos().into_opt(),
FieldPathElem::Ident(id) => id.pos.into_opt(),
FieldPathElem::Expr(rt) => rt.pos.into_opt(),
})
.reduce(|acc, pos| {
@ -221,7 +221,7 @@ impl UniRecord {
_ => {
// Position of identifiers must always be set at this stage
// (parsing)
let span_id = id.pos().unwrap();
let span_id = id.pos.unwrap();
let term_pos = rt.pos.into_opt().unwrap_or(span_id);
Err(InvalidRecordTypeError(TermPos::Original(
RawSpan::fuse(span_id, term_pos).unwrap(),
@ -362,7 +362,7 @@ pub fn fix_type_vars(ty: &mut Types) {
AbsType::Var(ref mut id) => {
if !bound_vars.contains(id) {
let id = *id;
let pos = id.pos();
let pos = id.pos;
ty.0 = AbsType::Flat(RichTerm::new(Term::Var(id), pos));
}
}

View File

@ -164,14 +164,14 @@ pub struct UnboundTypeVariableError(pub Ident);
impl From<UnboundTypeVariableError> for TypecheckError {
fn from(err: UnboundTypeVariableError) -> Self {
let pos = err.0.pos();
let pos = err.0.pos;
TypecheckError::UnboundTypeVariable(err.0, pos)
}
}
impl From<UnboundTypeVariableError> for ParseError {
fn from(err: UnboundTypeVariableError) -> Self {
let pos = err.0.pos();
let pos = err.0.pos;
ParseError::UnboundTypeVariables(vec![err.0], pos.unwrap())
}
}