Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/elaborator/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ impl Elaborator<'_> {
let typ = self.resolve_type(path.typ);
let check_self_param = false;

self.interner.push_type_ref_location(&typ, object_location);

let Some(method) = self.lookup_method(
&typ,
path.item.as_str(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Elaborator<'_> {
match resolved_type {
Type::DataType(ref data_type, _) => {
// Record the location of the type reference
self.interner.push_type_ref_location(resolved_type.clone(), location);
self.interner.push_type_ref_location(&resolved_type, location);
if !is_synthetic {
self.interner.add_type_reference(
data_type.borrow().id,
Expand Down
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@
interned_statement_kinds: noirc_arena::Arena<StatementKind>,

// Interned `UnresolvedTypeData`s during comptime code.
interned_unresolved_type_datas: noirc_arena::Arena<UnresolvedTypeData>,

Check warning on line 218 in compiler/noirc_frontend/src/node_interner.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (datas)

// Interned `Pattern`s during comptime code.
interned_patterns: noirc_arena::Arena<Pattern>,

/// Determins whether to run in LSP mode. In LSP mode references are tracked.

Check warning on line 223 in compiler/noirc_frontend/src/node_interner.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Determins)
pub(crate) lsp_mode: bool,

/// Whether to avoid comptime println from producing output
Expand Down Expand Up @@ -703,7 +703,7 @@
quoted_types: Default::default(),
interned_expression_kinds: Default::default(),
interned_statement_kinds: Default::default(),
interned_unresolved_type_datas: Default::default(),

Check warning on line 706 in compiler/noirc_frontend/src/node_interner.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (datas)
interned_patterns: Default::default(),
lsp_mode: false,
disable_comptime_printing: false,
Expand Down Expand Up @@ -876,8 +876,12 @@
}

/// Store [Location] of [Type] reference
pub fn push_type_ref_location(&mut self, typ: Type, location: Location) {
self.type_ref_locations.push((typ, location));
pub fn push_type_ref_location(&mut self, typ: &Type, location: Location) {
if !self.is_in_lsp_mode() {
return;
}

self.type_ref_locations.push((typ.clone(), location));
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -2189,11 +2193,11 @@
&mut self,
typ: UnresolvedTypeData,
) -> InternedUnresolvedTypeData {
InternedUnresolvedTypeData(self.interned_unresolved_type_datas.insert(typ))

Check warning on line 2196 in compiler/noirc_frontend/src/node_interner.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (datas)
}

pub fn get_unresolved_type_data(&self, id: InternedUnresolvedTypeData) -> &UnresolvedTypeData {
&self.interned_unresolved_type_datas[id.0]

Check warning on line 2200 in compiler/noirc_frontend/src/node_interner.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (datas)
}

/// Returns the type of an operator (which is always a function), along with its return type.
Expand Down
10 changes: 9 additions & 1 deletion compiler/noirc_frontend/src/parser/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{Expression, IntegerBitSize, ItemVisibility};
use crate::ast::{Expression, IntegerBitSize, ItemVisibility, UnresolvedType};
use crate::lexer::errors::LexerErrorKind;
use crate::lexer::token::Token;
use crate::token::TokenKind;
Expand Down Expand Up @@ -119,6 +119,10 @@ pub enum ParserErrorReason {
MissingParametersForFunctionDefinition,
#[error("`StructDefinition` is deprecated. It has been renamed to `TypeDefinition`")]
StructDefinitionDeprecated,
#[error("Missing angle brackets surrounding type in associated item path")]
MissingAngleBrackets,
#[error("Expected value, found built-in type `{typ}`")]
ExpectedValueFoundBuiltInType { typ: UnresolvedType },
}

/// Represents a parsing error, or a parsing error in the making.
Expand Down Expand Up @@ -313,6 +317,10 @@ impl<'a> From<&'a ParserError> for Diagnostic {
ParserErrorReason::StructDefinitionDeprecated => {
Diagnostic::simple_warning(format!("{reason}"), String::new(), error.location())
}
ParserErrorReason::MissingAngleBrackets => {
let secondary = "Types that don't start with an identifier need to be surrounded with angle brackets: `<`, `>`".to_string();
Diagnostic::simple_error(format!("{reason}"), secondary, error.location())
}
other => {
Diagnostic::simple_error(format!("{other}"), String::new(), error.location())
}
Expand Down
Loading
Loading