Skip to content

Commit

Permalink
frontend: Fully remove old and temporary class syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Nov 6, 2024
1 parent e3cac34 commit 8ea5d7b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 85 deletions.
4 changes: 2 additions & 2 deletions dora-frontend/src/clsdefck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tests {
#[test]
fn test_class_definition() {
ok("class Foo");
ok("class Foo&()");
ok("class Foo()");
ok("class Foo { a: Int32 }");
ok("class Foo { a: Int32, b:Int32 }");
ok("class Foo { a: Foo }");
Expand Down Expand Up @@ -80,7 +80,7 @@ mod tests {
fn alias_type_as_class_field() {
ok("
type MyInt = Int64;
class Foo&(MyInt)
class Foo(MyInt)
fn f(v: Int64): Foo {
Foo(v)
}
Expand Down
2 changes: 1 addition & 1 deletion dora-frontend/src/parsety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ mod tests {
fn class_type_with_named_type_arg() {
err(
"
class Foo[T]&(T)
class Foo[T](T)
fn f(x: Foo[T = Int64]) {}
",
(3, 25),
Expand Down
5 changes: 0 additions & 5 deletions dora-frontend/src/program_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,6 @@ impl<'x> visit::Visitor for TopLevelDeclaration<'x> {
for field in &node.fields {
check_modifiers(self.sa, self.file_id, &field.modifiers, &[Annotation::Pub]);
}

if node.field_name_style.is_old() {
self.sa
.warn(self.file_id, node.span, ErrorMessage::OldClassDefinition);
}
}

fn visit_struct(&mut self, node: &Arc<ast::Struct>) {
Expand Down
4 changes: 2 additions & 2 deletions dora-frontend/src/traitdefck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ mod tests {
"
trait A {}
trait B: A {}
class Foo[T]&(T)
class Foo[T](T)
impl[T] B for Foo[T] {}
",
(5, 21),
Expand All @@ -491,7 +491,7 @@ mod tests {
ok("
trait A {}
trait B: A {}
class Foo[T]&(T)
class Foo[T](T)
impl[T] B for Foo[T] {}
impl[T] A for Foo[T] {}
");
Expand Down
10 changes: 0 additions & 10 deletions dora-frontend/src/typeck/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,6 @@ 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 @@ -622,11 +617,6 @@ 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
50 changes: 25 additions & 25 deletions dora-frontend/src/typeck/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn type_unknown_method() {
#[test]
fn type_ctor() {
ok("class Foo fn f(): Foo { return Foo(); }");
ok("class Foo&(Int32) fn f(): Foo { return Foo(1i32); }");
ok("class Foo(Int32) fn f(): Foo { return Foo(1i32); }");
err(
"class Foo fn f(): Foo { return 1i32; }",
(1, 25),
Expand Down Expand Up @@ -1131,7 +1131,7 @@ fn test_ctor_with_type_param() {
}
}
class Bar[T]&(T)
class Bar[T](T)
",
(5, 28),
ErrorMessage::WrongTypeForArgument("T".into(), "Int32".into()),
Expand Down Expand Up @@ -2214,15 +2214,15 @@ fn extension_method_call() {
#[test]
fn extension_class_with_type_param() {
ok("
class Foo[T]&(T)
class Foo[T](T)
trait MyTrait {}
impl[T: MyTrait] Foo[T] { fn foo(): Int32 { 12i32 } }
impl MyTrait for Int32 {}
fn bar(x: Foo[Int32]): Int32 { x.foo() }
");

ok("
class Foo[T]&(T)
class Foo[T](T)
impl Foo[Int32] { fn foo() {} }
impl Foo[Float32] { fn bar() {} }
fn f(x: Foo[Int32]) { x.foo() }
Expand All @@ -2231,7 +2231,7 @@ fn extension_class_with_type_param() {

err(
"
class Foo[T]&(T)
class Foo[T](T)
impl Foo[Float32] { fn bar() {} }
fn f(x: Foo[Int32]) { x.bar() }
",
Expand All @@ -2243,7 +2243,7 @@ fn extension_class_with_type_param() {
#[test]
fn extension_class_tuple() {
ok("
class Foo[T]&(T)
class Foo[T](T)
impl Foo[(Int32, Int32)] {
fn bar() {}
}
Expand Down Expand Up @@ -3063,7 +3063,7 @@ fn mod_impl() {
fn mod_class() {
ok("
mod foo {
class Foo&(Bar)
class Foo(Bar)
impl Foo {
fn foo(x: Bar) {}
}
Expand All @@ -3076,7 +3076,7 @@ fn mod_class() {
fn mod_class_new() {
ok("
mod foo {
class Foo&(Bar)
class Foo(Bar)
class Bar
}
");
Expand All @@ -3085,7 +3085,7 @@ fn mod_class_new() {
"
fn f() { foo::Foo(1i32); }
mod foo {
class Foo&(Int32)
class Foo(Int32)
}
",
(2, 18),
Expand All @@ -3096,7 +3096,7 @@ fn mod_class_new() {
"
fn f() { foo::Foo(1i32); }
mod foo {
class Foo&(pub Int32)
class Foo(pub Int32)
}
",
(2, 18),
Expand All @@ -3107,7 +3107,7 @@ fn mod_class_new() {
"
fn f() { foo::Foo(1i32); }
mod foo {
pub class Foo&(Int32)
pub class Foo(Int32)
}
",
(2, 18),
Expand Down Expand Up @@ -4342,7 +4342,7 @@ fn pattern_in_expression() {
#[test]
fn pattern_class_with_args() {
ok("
class Foo&(Int64, String)
class Foo(Int64, String)
fn f(x: Foo): Int64 {
let Foo(a, b) = x;
a
Expand All @@ -4351,8 +4351,8 @@ fn pattern_class_with_args() {

err(
"
class Foo&(Int64, String)
class Bar&(Int64, String)
class Foo(Int64, String)
class Bar(Int64, String)
fn f(x: Foo): Int64 {
let Bar(a, b) = x;
b
Expand All @@ -4364,7 +4364,7 @@ fn pattern_class_with_args() {

err(
"
class Foo&(Int64)
class Foo(Int64)
fn f(x: Foo): Int64 {
let Foo(a, b) = x;
b
Expand All @@ -4386,7 +4386,7 @@ fn pattern_class_no_args() {

err(
"
class Foo &(Int64)
class Foo(Int64)
fn f(x: Foo) {
let Foo = x;
}
Expand Down Expand Up @@ -4475,7 +4475,7 @@ fn pattern_class_private_ctor() {
err(
"
mod n {
pub class Foo&(pub Int64, String)
pub class Foo(pub Int64, String)
}
fn f(x: n::Foo): Int64 {
let n::Foo(a, b) = x;
Expand Down Expand Up @@ -4756,22 +4756,22 @@ fn class_ctor_with_ident_expr_used_as_named_argument() {
#[test]
fn unnamed_class_field() {
ok("
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo): Int {
x.0
}
");

ok("
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo): Bool {
x.1
}
");

err(
"
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo): Bool {
x.2
}
Expand All @@ -4783,7 +4783,7 @@ fn unnamed_class_field() {
err(
"
mod m {
pub class Foo &(Int, Bool)
pub class Foo(Int, Bool)
}
fn f(x: m::Foo): Int {
Expand All @@ -4798,22 +4798,22 @@ fn unnamed_class_field() {
#[test]
fn unnamed_class_field_assignment() {
ok("
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo, v: Int) {
x.0 = v;
}
");

ok("
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo, v: Bool) {
x.1 = v;
}
");

err(
"
class Foo &(Int, Bool)
class Foo(Int, Bool)
fn f(x: Foo, v: String) {
x.2 = v;
}
Expand All @@ -4825,7 +4825,7 @@ fn unnamed_class_field_assignment() {
err(
"
mod m {
pub class Foo &(Int, Bool)
pub class Foo(Int, Bool)
}
fn f(x: m::Foo, v: Int) {
Expand Down
8 changes: 0 additions & 8 deletions dora-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ pub struct Struct {
pub enum FieldNameStyle {
Named,
Positional,
Old,
}

impl FieldNameStyle {
Expand All @@ -335,13 +334,6 @@ impl FieldNameStyle {
}
}

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

pub fn is_positional(&self) -> bool {
match self {
FieldNameStyle::Positional => true,
Expand Down
37 changes: 5 additions & 32 deletions dora-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,7 @@ impl Parser {
let where_bounds = self.parse_where();
let field_name_style;

let fields = if self.is2(AND, L_PAREN) {
self.assert(AND);
let fields = if self.is(L_PAREN) {
field_name_style = FieldNameStyle::Positional;

self.parse_list(
Expand All @@ -736,24 +735,6 @@ impl Parser {
}
},
)
} else if self.is(L_PAREN) {
field_name_style = FieldNameStyle::Old;

self.parse_list(
L_PAREN,
COMMA,
R_PAREN,
ELEM_FIRST,
ParseError::ExpectedField,
LIST,
|p| {
if p.is_set(FIELD_FIRST) {
Some(p.parse_named_field())
} else {
None
}
},
)
} else if self.is(L_BRACE) {
field_name_style = FieldNameStyle::Named;

Expand Down Expand Up @@ -3349,22 +3330,14 @@ mod tests {

#[test]
fn parse_class_with_param() {
let prog = parse("class Foo(a: int)");
let class = prog.cls0();
assert_eq!(1, class.fields.len());
}

#[test]
fn parse_class_with_param_var() {
let prog = parse("class Foo(a: int)");
let prog = parse("class Foo{a: int}");
let class = prog.cls0();

assert_eq!(1, class.fields.len());
}

#[test]
fn parse_class_with_params() {
let prog = parse("class Foo(a: int, b: int)");
let prog = parse("class Foo{a: int, b: int}");
let class = prog.cls0();

assert_eq!(2, class.fields.len());
Expand All @@ -3376,7 +3349,7 @@ mod tests {
let class = prog.cls0();
assert_eq!(class.fields.len(), 2);

let prog = parse("class Foo(a: Int64, b: Bool)");
let prog = parse("class Foo { a: Int64, b: Bool }");
let class = prog.cls0();
assert_eq!(class.fields.len(), 2);

Expand Down Expand Up @@ -3473,7 +3446,7 @@ mod tests {

#[test]
fn parse_class_unnamed() {
let prog = parse("class Foo &(A, B)");
let prog = parse("class Foo(A, B)");
let cls = prog.cls0();
assert_eq!(2, cls.fields.len());
assert_eq!("Foo", cls.name.as_ref().unwrap().name_as_string);
Expand Down

0 comments on commit 8ea5d7b

Please sign in to comment.