Skip to content

Commit

Permalink
Fix compilation errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Dec 20, 2024
1 parent cf8147e commit bd062da
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
6 changes: 2 additions & 4 deletions cli/src/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ use nickel_lang_core::{
label::Label,
match_sharedterm, mk_app, mk_fun,
program::Program,
term::{
make, record::RecordData, LabeledType, RichTerm, Term, Traverse as _, TraverseOrder,
TypeAnnotation,
},
term::{make, record::RecordData, LabeledType, RichTerm, Term, TypeAnnotation},
traverse::{Traverse as _, TraverseOrder},
typ::{Type, TypeF},
typecheck::TypecheckMode,
};
Expand Down
8 changes: 8 additions & 0 deletions core/src/bytecode/ast/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ impl<'ast> Type<'ast> {
pub fn with_pos(self, pos: TermPos) -> Type<'ast> {
Type { pos, ..self }
}

/// Searches for a [crate::typ::TypeF]. If one is found, returns the term it contains.
pub fn find_contract(&self) -> Option<&'ast Ast<'ast>> {
self.find_map(|ty: &Type| match &ty.typ {
TypeF::Contract(f) => Some(*f),
_ => None,
})
}
}

impl<'ast> TypeUnr<'ast> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/bytecode/typecheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ fn check<'ast, V: TypecheckVisitor<'ast>>(
// .map_err(|err| err.into_typecheck_err(state, ast.pos))
// }
Node::Type(typ) => {
if let Some(contract) = typ.typ.find_contract() {
if let Some(contract) = typ.find_contract() {
todo!("needs to update `error::TypecheckError` first, but not ready to switch to the new typechecker yet")
// Err(TypecheckError::CtrTypeInTermPos {
// contract,
Expand Down
5 changes: 2 additions & 3 deletions core/src/bytecode/typecheck/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use super::*;
use crate::{
bytecode::ast::{
builder,
primop::{PrimOp, RecordOpKind},
primop::PrimOp,
AstAlloc,
},
error::TypecheckError,
label::{Polarity, TypeVarData},
position::TermPos,
term::{BinaryOp, NAryOp, RecordExtKind, UnaryOp},
typ::TypeF,
};

use crate::{mk_buty_arrow, mk_buty_enum, mk_buty_record};

pub trait PrimOpType {
Expand Down
6 changes: 3 additions & 3 deletions core/src/bytecode/typecheck/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ impl<'ast> Combine for ResolvedRecord<'ast> {

/// A wrapper type around a record that has been resolved but hasn't yet got a position. This is
/// done to force the caller of [Record::resolve] to provide a position before doing anything else.
pub struct PoslessResolvedRecord<'ast>(ResolvedRecord<'ast>);
pub(super) struct PoslessResolvedRecord<'ast>(ResolvedRecord<'ast>);

impl<'ast> PoslessResolvedRecord<'ast> {
pub fn new(
pub(super) fn new(
stat_fields: IndexMap<LocIdent, ResolvedField<'ast>>,
dyn_fields: Vec<(&'ast Ast<'ast>, ResolvedField<'ast>)>,
) -> Self {
Expand All @@ -284,7 +284,7 @@ impl<'ast> PoslessResolvedRecord<'ast> {
})
}

pub fn with_pos(self, pos: TermPos) -> ResolvedRecord<'ast> {
pub(super) fn with_pos(self, pos: TermPos) -> ResolvedRecord<'ast> {
let PoslessResolvedRecord(record) = self;

ResolvedRecord { pos, ..record }
Expand Down
1 change: 0 additions & 1 deletion core/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::{
position::{RawSpan, TermPos},
pretty::PrettyPrintCap,
traverse::*,
traverse::{Traverse, TraverseControl, TraverseOrder},
typ::{Type, UnboundTypeVariableError},
typecheck::eq::{contract_eq, type_eq_noenv},
};
Expand Down
14 changes: 3 additions & 11 deletions core/src/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ pub enum TypeF<Ty, RRows, ERows, Te> {
/// Concrete, recursive definition for an enum row.
pub type EnumRow = EnumRowF<Box<Type>>;
/// Concrete, recursive definition for enum rows.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct EnumRows(pub EnumRowsF<Box<Type>, Box<EnumRows>>);
/// Concrete, recursive definition for a record row.
pub type RecordRow = RecordRowF<Box<Type>>;
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Debug)]
/// Concrete, recursive definition for record rows.
pub struct RecordRows(pub RecordRowsF<Box<Type>, Box<RecordRows>>);

/// Concrete, recursive type for a Nickel type.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct Type {
pub typ: TypeF<Box<Type>, RecordRows, EnumRows, RichTerm>,
pub pos: TermPos,
Expand Down Expand Up @@ -678,14 +678,6 @@ impl<Ty, RRows, ERows, Te> TypeF<Ty, RRows, ERows, Te> {
pub fn is_contract(&self) -> bool {
matches!(self, TypeF::Contract(_))
}

/// Searches for a `TypeF::Contract`. If one is found, returns the term it contains.
pub fn find_contract(&self) -> Option<&Te> {
self.find_map(|ty: &Type| match &ty.typ {
TypeF::Contract(f) => Some(f),
_ => None,
})
}
}

impl Traverse<Type> for RecordRows {
Expand Down
3 changes: 2 additions & 1 deletion lsp/nls/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use nickel_lang_core::{
files::FileId,
identifier::Ident,
position::RawSpan,
term::{BinaryOp, RichTerm, Term, Traverse, TraverseControl, UnaryOp},
term::{BinaryOp, RichTerm, Term, UnaryOp},
traverse::{Traverse, TraverseControl},
typ::{Type, TypeF},
typecheck::{
reporting::{NameReg, ToType},
Expand Down
5 changes: 3 additions & 2 deletions lsp/nls/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use codespan::ByteIndex;
use lsp_types::{TextDocumentPositionParams, Url};
use nickel_lang_core::cache::InputFormat;
use nickel_lang_core::term::{RichTerm, Term, Traverse};
use nickel_lang_core::{
cache::InputFormat,
cache::{Cache, CacheError, CacheOp, EntryState, SourcePath, TermEntry},
error::{Error, ImportError},
files::FileId,
position::RawPos,
term::{RichTerm, Term},
traverse::Traverse,
typecheck::{self},
};

Expand Down
3 changes: 2 additions & 1 deletion lsp/nls/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::ops::Range;
use codespan::ByteIndex;
use nickel_lang_core::{
position::TermPos,
term::{pattern::bindings::Bindings, RichTerm, Term, Traverse, TraverseControl},
term::{pattern::bindings::Bindings, RichTerm, Term},
traverse::{Traverse, TraverseControl},
};

use crate::{identifier::LocIdent, term::RichTermPtr};
Expand Down
3 changes: 2 additions & 1 deletion lsp/nls/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use nickel_lang_core::{
environment::Environment as GenericEnvironment,
identifier::Ident,
position::RawSpan,
term::{pattern::bindings::Bindings, MatchData, RichTerm, Term, Traverse, TraverseControl},
term::{pattern::bindings::Bindings, MatchData, RichTerm, Term},
traverse::{Traverse, TraverseControl},
};

use crate::{field_walker::Def, identifier::LocIdent};
Expand Down

0 comments on commit bd062da

Please sign in to comment.