From 0f9c237c881cd764f405232fae16b9a329dc5f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Fri, 1 Nov 2024 08:30:54 +0100 Subject: [PATCH] frontend: Report warnings for named field access with unnamed ctor --- dora-frontend/src/error/msg.rs | 4 ++++ dora-frontend/src/typeck/expr.rs | 10 ++++++++++ dora-parser/src/ast.rs | 7 +++++++ pkgs/boots/compilation.dora | 16 ++++++++-------- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/dora-frontend/src/error/msg.rs b/dora-frontend/src/error/msg.rs index 943f5d617..230a0fe28 100644 --- a/dora-frontend/src/error/msg.rs +++ b/dora-frontend/src/error/msg.rs @@ -208,6 +208,7 @@ pub enum ErrorMessage { WrongTypeForArgument(String, String), SuperfluousArgument, MissingArguments(usize, usize), + FieldShouldBeUnnamed, } impl ErrorMessage { @@ -721,6 +722,9 @@ impl ErrorMessage { expected, got ) } + ErrorMessage::FieldShouldBeUnnamed => { + format!("Field access should be unnamed.") + } } } } diff --git a/dora-frontend/src/typeck/expr.rs b/dora-frontend/src/typeck/expr.rs index 0560387d4..5a4f88b05 100644 --- a/dora-frontend/src/typeck/expr.rs +++ b/dora-frontend/src/typeck/expr.rs @@ -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; } @@ -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; } diff --git a/dora-parser/src/ast.rs b/dora-parser/src/ast.rs index 2d69ed9a1..bb0f47c6f 100644 --- a/dora-parser/src/ast.rs +++ b/dora-parser/src/ast.rs @@ -334,6 +334,13 @@ impl FieldNameStyle { _ => false, } } + + pub fn is_old(&self) -> bool { + match self { + FieldNameStyle::Old => true, + _ => false, + } + } } pub type WhereBounds = Arc; diff --git a/pkgs/boots/compilation.dora b/pkgs/boots/compilation.dora index 5906ea6b6..7a97aa3e0 100644 --- a/pkgs/boots/compilation.dora +++ b/pkgs/boots/compilation.dora @@ -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], @@ -17,7 +17,7 @@ pub class CompilationInfo( displayName: Option[String], inlinedFunctions: Vec[iface::InlinedFunction], byteWriter: ByteWriter, -) +} impl CompilationInfo { pub static fn new( @@ -33,7 +33,7 @@ impl CompilationInfo { ): CompilationInfo { CompilationInfo( bc, - Some[FunctionId](id), + fctId = Some[FunctionId](id), typeParams, returnType, loc, @@ -41,11 +41,11 @@ impl CompilationInfo { 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(), ) }