Skip to content

Commit

Permalink
Disallow a couple of new features (#393)
Browse files Browse the repository at this point in the history
* Disallow a couple of new features
  • Loading branch information
jamescourtney authored Aug 5, 2023
1 parent eb85287 commit be4ab5c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 23 deletions.
35 changes: 14 additions & 21 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,7 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- if: runner.os == 'Linux'
name: chmod flatc (linux)
working-directory: src/ext/flatc
run: |
chmod 755 linux/flatc
shell: bash

- if: runner.os == 'MacOS'
name: chmod flatc (mac)
working-directory: src/ext/flatc
run: |
chmod 755 macos_arm/flatc
chmod 755 macos_intel/flatc
shell: bash


- name: Restore dependencies
working-directory: src
run: dotnet restore
Expand Down Expand Up @@ -75,15 +60,23 @@ jobs:
working-directory: src
run: dotnet build -c Release /p:SignAssembly=true

- if: runner.os == 'Windows'
name: Test (All)
working-directory: src
- name: E2E Test
working-directory: src/Tests/FlatSharpEndToEndTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal

- name: Test (E2E)
working-directory: src/Tests/FlatSharpEndToEndTests
- name: Poolable E2E Test
working-directory: src/Tests/FlatSharpPoolableEndToEndTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal

- name: Compiler Test
working-directory: src/Tests/FlatSharpCompilerTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal

- if: runner.os == 'Windows'
name: Legacy Test
working-directory: src/Tests/FlatSharpTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal

- if: runner.os == 'Windows'
name: Upload Packages
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion src/FlatSharp.Compiler/MetadataKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ public static class MetadataKeys

public static IEnumerable<string> UnsupportedStandardAttributes => new[]
{
"force_align", "flexbuffer", "hash", "original_order"
"force_align", "flexbuffer", "hash", "original_order", "vector64"
};
}
2 changes: 2 additions & 0 deletions src/FlatSharp.Compiler/Schema/BaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace FlatSharp.Compiler.Schema;
public enum BaseType : byte
{
None,

UType,
Bool,
Byte,
Expand All @@ -39,6 +40,7 @@ public enum BaseType : byte
Obj, // Used for tables & structs.
Union,
Array,
Vector64,

// Add any new type above this value.
MaxBaseType
Expand Down
5 changes: 5 additions & 0 deletions src/FlatSharp/TypeModel/StructMemberModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ internal override void Validate()
{
throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the SharedString attribute. SharedString is not valid inside structs.");
}

if (this.Attribute.Key)
{
throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the 'key' attribute. FlatSharp does not support keys on struct members.");
}
}

/// <summary>
Expand Down
27 changes: 27 additions & 0 deletions src/Tests/FlatSharpCompilerTests/InvalidAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

using FlatSharp.TypeModel;

namespace FlatSharpTests.Compiler;

public class InvalidAttributeTests
Expand Down Expand Up @@ -42,6 +44,18 @@ struct Foo { Value : [int : 4] (force_align: 2); }
Assert.Contains("FlatSharp does not support the 'force_align' attribute.", ex.Message);
}

[Fact]
public void UnsupportedAttribute_Vector64()
{
string schema = @"
namespace ns;
table Foo { Value : [ int ] (vector64); }
";

var ex = Assert.Throws<InvalidFbsFileException>(() => FlatSharpCompiler.CompileAndLoadAssembly(schema, new()));
Assert.Contains("FlatSharp does not support the 'vector64' attribute.", ex.Message);
}

[Fact]
public void UnsupportedAttribute_ForceAlign_TableField()
{
Expand Down Expand Up @@ -116,6 +130,19 @@ namespace ns;
Assert.Contains("FlatSharp does not support the 'original_order' attribute.", ex.Message);
}

[Fact]
public void UnsupportedAttribute_KeyOnStruct()
{
string schema = @$"
{MetadataHelpers.AllAttributes}
namespace ns;
struct Bar {{ k : int (key); }}
";

var ex = Assert.Throws<InvalidFlatBufferDefinitionException>(() => FlatSharpCompiler.CompileAndLoadAssembly(schema, new()));
Assert.Contains("Struct member 'ns.Bar.K' declared the 'key' attribute. FlatSharp does not support keys on struct members.", ex.Message);
}

[Fact]
public void FlatSharpEnumAttribute_FailsToParse()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/FlatSharpTests/ClassLib/TypeModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public void TypeModel_SortedVector_OfStruct_NotAllowed()
{
var ex = Assert.Throws<InvalidFlatBufferDefinitionException>(() =>
RuntimeTypeModel.CreateFrom(typeof(SortedVector<IList<SortedVectorKeyStruct<int>>>)));
Assert.Equal("Property 'Vector' declares a sorted vector, but the member is not a table. Type = System.Collections.Generic.IList<FlatSharpTests.TypeModelTests.SortedVectorKeyStruct<System.Int32>>.", ex.Message);
Assert.Equal("Struct member 'FlatSharpTests.TypeModelTests.SortedVectorKeyStruct<System.Int32>.Key' declared the 'key' attribute. FlatSharp does not support keys on struct members.", ex.Message);
}

[Fact]
Expand Down
Empty file modified src/ext/flatc/macos_arm/flatc
100644 → 100755
Empty file.
Empty file modified src/ext/flatc/macos_intel/flatc
100644 → 100755
Empty file.

0 comments on commit be4ab5c

Please sign in to comment.