From 362a43a4e6b7358847794d4e1581f694b10000c6 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 22 Nov 2023 14:07:33 -0500 Subject: [PATCH] Interfaces can no longer be used as types. (#675) --- src/ast/node.rs | 2 -- src/grammar/elements/exception.rs | 5 +++++ src/grammar/elements/interface.rs | 21 ++------------------- src/grammar/wrappers.rs | 2 +- src/patchers/encoding_patcher.rs | 4 ---- src/validators/dictionary.rs | 9 ++++----- src/validators/members.rs | 1 - tests/dictionaries/key_type.rs | 1 - tests/interfaces/mod.rs | 15 --------------- tests/mixed_encoding_tests.rs | 5 ----- tests/optional_tests.rs | 2 -- tests/typealias_tests.rs | 1 - 12 files changed, 12 insertions(+), 56 deletions(-) diff --git a/src/ast/node.rs b/src/ast/node.rs index a9bbc178..5d4d02d4 100644 --- a/src/ast/node.rs +++ b/src/ast/node.rs @@ -97,7 +97,6 @@ impl<'a> TryFrom<&'a Node> for WeakPtr { match node { Node::Struct(struct_ptr) => Ok(downgrade_as!(struct_ptr, dyn Type)), Node::Class(class_ptr) => Ok(downgrade_as!(class_ptr, dyn Type)), - Node::Interface(interface_ptr) => Ok(downgrade_as!(interface_ptr, dyn Type)), Node::Enum(enum_ptr) => Ok(downgrade_as!(enum_ptr, dyn Type)), Node::CustomType(custom_type_ptr) => Ok(downgrade_as!(custom_type_ptr, dyn Type)), Node::TypeAlias(type_alias_ptr) => Ok(downgrade_as!(type_alias_ptr, dyn Type)), @@ -124,7 +123,6 @@ impl<'a> TryFrom<&'a Node> for &'a dyn Type { match node { Node::Struct(struct_ptr) => Ok(struct_ptr.borrow()), Node::Class(class_ptr) => Ok(class_ptr.borrow()), - Node::Interface(interface_ptr) => Ok(interface_ptr.borrow()), Node::Enum(enum_ptr) => Ok(enum_ptr.borrow()), Node::CustomType(custom_type_ptr) => Ok(custom_type_ptr.borrow()), Node::TypeAlias(type_alias_ptr) => Ok(type_alias_ptr.borrow()), diff --git a/src/grammar/elements/exception.rs b/src/grammar/elements/exception.rs index c5ac91af..53b6b476 100644 --- a/src/grammar/elements/exception.rs +++ b/src/grammar/elements/exception.rs @@ -39,6 +39,11 @@ impl Exception { pub fn base_exception(&self) -> Option<&Exception> { self.base.as_ref().map(TypeRef::definition) } + + // This intentionally shadows the trait method of the same name on `Type`. + pub fn supported_encodings(&self) -> SupportedEncodings { + self.supported_encodings.clone().unwrap() + } } implement_Element_for!(Exception, "exception"); diff --git a/src/grammar/elements/interface.rs b/src/grammar/elements/interface.rs index 89c3de70..00513c71 100644 --- a/src/grammar/elements/interface.rs +++ b/src/grammar/elements/interface.rs @@ -61,26 +61,9 @@ impl Interface { all_bases } -} - -impl Type for Interface { - fn type_string(&self) -> String { - self.identifier().to_owned() - } - - fn fixed_wire_size(&self) -> Option { - None - } - - fn is_class_type(&self) -> bool { - false - } - - fn tag_format(&self) -> Option { - Some(TagFormat::FSize) - } - fn supported_encodings(&self) -> SupportedEncodings { + // This intentionally shadows the trait method of the same name on `Type`. + pub fn supported_encodings(&self) -> SupportedEncodings { self.supported_encodings.clone().unwrap() } } diff --git a/src/grammar/wrappers.rs b/src/grammar/wrappers.rs index 028b3b5a..46a62230 100644 --- a/src/grammar/wrappers.rs +++ b/src/grammar/wrappers.rs @@ -112,4 +112,4 @@ pub trait AsTypes { fn concrete_type(&self) -> Types; } -generate_types_wrapper!(Struct, Class, Interface, Enum, CustomType, Sequence, Dictionary, Primitive); +generate_types_wrapper!(Struct, Class, Enum, CustomType, Sequence, Dictionary, Primitive); diff --git a/src/patchers/encoding_patcher.rs b/src/patchers/encoding_patcher.rs index 92338a7a..d2f86f87 100644 --- a/src/patchers/encoding_patcher.rs +++ b/src/patchers/encoding_patcher.rs @@ -136,10 +136,6 @@ impl EncodingPatcher<'_> { allow_nullable_with_slice_1 = true; self.get_supported_encodings_for(class_def) } - Types::Interface(interface_def) => { - allow_nullable_with_slice_1 = true; - self.get_supported_encodings_for(interface_def) - } Types::Enum(enum_def) => self.get_supported_encodings_for(enum_def), Types::CustomType(custom_type) => { allow_nullable_with_slice_1 = true; diff --git a/src/validators/dictionary.rs b/src/validators/dictionary.rs index 862c13df..babfdb7f 100644 --- a/src/validators/dictionary.rs +++ b/src/validators/dictionary.rs @@ -49,7 +49,6 @@ fn check_dictionary_key_type(type_ref: &TypeRef) -> Option { true } Types::Class(_) => false, - Types::Interface(_) => false, Types::Enum(_) => true, Types::CustomType(_) => true, Types::Sequence(_) => false, @@ -71,9 +70,9 @@ fn check_dictionary_key_type(type_ref: &TypeRef) -> Option { } fn formatted_kind(definition: &dyn Type) -> String { - match definition.concrete_type() { - Types::Class(c) => format!("{} '{}'", c.kind(), c.identifier()), - Types::Interface(i) => format!("{} '{}'", i.kind(), i.identifier()), - _ => definition.kind().to_owned(), + if let Types::Class(class_def) = definition.concrete_type() { + format!("class '{}'", class_def.identifier()) + } else { + definition.kind().to_owned() } } diff --git a/src/validators/members.rs b/src/validators/members.rs index 08af71e5..834a29fe 100644 --- a/src/validators/members.rs +++ b/src/validators/members.rs @@ -57,7 +57,6 @@ fn tagged_members_cannot_use_classes(members: Vec<&impl Member>, diagnostics: &m match typeref.definition().concrete_type() { Types::Struct(struct_def) => struct_def.fields().iter().any(|m| uses_classes(&m.data_type)), Types::Class(_) => true, - Types::Interface(_) => false, Types::Enum(_) => false, Types::CustomType(_) => false, Types::Sequence(sequence) => uses_classes(&sequence.element_type), diff --git a/tests/dictionaries/key_type.rs b/tests/dictionaries/key_type.rs index 758661e1..27a67e5d 100644 --- a/tests/dictionaries/key_type.rs +++ b/tests/dictionaries/key_type.rs @@ -108,7 +108,6 @@ fn allowed_constructed_types(key_type: &str, key_type_def: &str) { } #[test_case("MyClass", "class", "Slice1"; "classes")] -#[test_case("MyInterface", "interface", "Slice2"; "interfaces")] fn disallowed_constructed_types(key_type: &str, key_kind: &str, mode: &str) { // Arrange let slice = format!( diff --git a/tests/interfaces/mod.rs b/tests/interfaces/mod.rs index 8563e351..d21f4ee4 100644 --- a/tests/interfaces/mod.rs +++ b/tests/interfaces/mod.rs @@ -26,21 +26,6 @@ fn can_have_no_operations() { assert_eq!(interface_def.operations().len(), 0); } -#[test] -fn can_have_self_referencing_operations() { - // Arrange - let slice = " - module Test - - interface I { - myOp() -> I - } - "; - - // Act/Assert - assert_parses(slice); -} - #[test] fn can_have_one_operation() { // Arrange diff --git a/tests/mixed_encoding_tests.rs b/tests/mixed_encoding_tests.rs index 1ce4634e..cfc08f0e 100644 --- a/tests/mixed_encoding_tests.rs +++ b/tests/mixed_encoding_tests.rs @@ -21,17 +21,12 @@ fn valid_mixed_compilation_mode_succeeds() { A B } - - interface AnInterface { - op() -> AnEnum - } "; let slice2 = " mode = Slice2 module Test struct AStruct { e: AnEnum - i: AnInterface c: ACompactStruct } "; diff --git a/tests/optional_tests.rs b/tests/optional_tests.rs index 86eb65fc..4626ed25 100644 --- a/tests/optional_tests.rs +++ b/tests/optional_tests.rs @@ -125,7 +125,6 @@ mod optional { } #[test_case("class Foo {}"; "class")] - #[test_case("interface Foo {}"; "interface")] #[test_case("custom Foo"; "custom type")] fn optional_user_defined_types_are_allowed(definition: &str) { // Arrange @@ -447,7 +446,6 @@ mod optional { #[test_case("struct Foo {}"; "r#struct")] #[test_case("unchecked enum Foo: uint8 {}"; "r#enum")] - #[test_case("interface Foo {}"; "interface")] #[test_case("custom Foo"; "custom type")] fn optional_user_defined_types_are_allowed(definition: &str) { // Arrange diff --git a/tests/typealias_tests.rs b/tests/typealias_tests.rs index 4c0d48d8..cf7bb669 100644 --- a/tests/typealias_tests.rs +++ b/tests/typealias_tests.rs @@ -12,7 +12,6 @@ mod typealias { #[test_case("struct S {}", "S", "Slice2"; "structs")] #[test_case("class C {}", "C", "Slice1"; "classes")] - #[test_case("interface I {}", "I", "Slice2"; "interfaces")] #[test_case("enum E { Foo }", "E", "Slice1"; "enums")] #[test_case("custom C", "C", "Slice2"; "custom types")] #[test_case("", "bool", "Slice2"; "primitives")]