Skip to content

Commit

Permalink
frontend: Report warnings for named field access with unnamed ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Nov 1, 2024
1 parent afe42b4 commit 0f9c237
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions dora-frontend/src/error/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub enum ErrorMessage {
WrongTypeForArgument(String, String),
SuperfluousArgument,
MissingArguments(usize, usize),
FieldShouldBeUnnamed,
}

impl ErrorMessage {
Expand Down Expand Up @@ -721,6 +722,9 @@ impl ErrorMessage {
expected, got
)
}
ErrorMessage::FieldShouldBeUnnamed => {
format!("Field access should be unnamed.")
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions dora-frontend/src/typeck/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ pub(super) fn check_expr_dot(
ck.sa.report(ck.file_id, e.rhs.span(), msg);
}

if cls.field_name_style.is_old() {
let msg = ErrorMessage::FieldShouldBeUnnamed;
ck.sa.warn(ck.file_id, e.rhs.span(), msg);
}

ck.analysis.set_ty(e.id, fty.clone());
return fty;
}
Expand All @@ -458,6 +463,11 @@ pub(super) fn check_expr_dot(
ck.sa.report(ck.file_id, e.rhs.span(), msg);
}

if struct_.field_name_style.is_old() {
let msg = ErrorMessage::FieldShouldBeUnnamed;
ck.sa.warn(ck.file_id, e.rhs.span(), msg);
}

ck.analysis.set_ty(e.id, fty.clone());
return fty;
}
Expand Down
7 changes: 7 additions & 0 deletions dora-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ impl FieldNameStyle {
_ => false,
}
}

pub fn is_old(&self) -> bool {
match self {
FieldNameStyle::Old => true,
_ => false,
}
}
}

pub type WhereBounds = Arc<WhereBoundsData>;
Expand Down
16 changes: 8 additions & 8 deletions pkgs/boots/compilation.dora
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use package::bytecode::{BytecodeFunction, BytecodeType, FunctionId, Location};
use package::interface as iface;
use package::serializer::ByteWriter;

pub class CompilationInfo(
pub class CompilationInfo {
pub bc: BytecodeFunction,
pub fctId: Option[FunctionId],
pub typeParams: Array[BytecodeType],
Expand All @@ -17,7 +17,7 @@ pub class CompilationInfo(
displayName: Option[String],
inlinedFunctions: Vec[iface::InlinedFunction],
byteWriter: ByteWriter,
)
}

impl CompilationInfo {
pub static fn new(
Expand All @@ -33,19 +33,19 @@ impl CompilationInfo {
): CompilationInfo {
CompilationInfo(
bc,
Some[FunctionId](id),
fctId = Some[FunctionId](id),
typeParams,
returnType,
loc,
emitDebug,
emitGraph,
emitHtml,
emitCodeComments,
true,
true,
None[String],
Vec[iface::InlinedFunction]::new(),
ByteWriter::new(),
inline = true,
optimize = true,
displayName = None[String],
inlinedFunctions = Vec[iface::InlinedFunction]::new(),
byteWriter = ByteWriter::new(),
)
}

Expand Down

0 comments on commit 0f9c237

Please sign in to comment.