Skip to content

Commit

Permalink
Interfaces can no longer be used as types. (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Nov 22, 2023
1 parent c6f4ceb commit 362a43a
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 56 deletions.
2 changes: 0 additions & 2 deletions src/ast/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl<'a> TryFrom<&'a Node> for WeakPtr<dyn Type> {
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)),
Expand All @@ -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()),
Expand Down
5 changes: 5 additions & 0 deletions src/grammar/elements/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
21 changes: 2 additions & 19 deletions src/grammar/elements/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
None
}

fn is_class_type(&self) -> bool {
false
}

fn tag_format(&self) -> Option<TagFormat> {
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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 0 additions & 4 deletions src/patchers/encoding_patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/validators/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn check_dictionary_key_type(type_ref: &TypeRef) -> Option<Diagnostic> {
true
}
Types::Class(_) => false,
Types::Interface(_) => false,
Types::Enum(_) => true,
Types::CustomType(_) => true,
Types::Sequence(_) => false,
Expand All @@ -71,9 +70,9 @@ fn check_dictionary_key_type(type_ref: &TypeRef) -> Option<Diagnostic> {
}

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()
}
}
1 change: 0 additions & 1 deletion src/validators/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion tests/dictionaries/key_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
15 changes: 0 additions & 15 deletions tests/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/mixed_encoding_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
";
Expand Down
2 changes: 0 additions & 2 deletions tests/optional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/typealias_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 362a43a

Please sign in to comment.