From 0d72d26ab44c61b94b6ae022f10bee61e95865fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Mon, 18 Sep 2023 23:52:14 +0200 Subject: [PATCH] Update a few comments --- internal/ast/compiler/disjunctions.go | 2 +- internal/ast/compiler/disjunctions_test.go | 6 +++--- internal/ast/hints.go | 4 ++-- internal/ast/types.go | 6 +++--- internal/jennies/golang/rawtypes.go | 4 ++-- ....tmpl => disjunction_of_refs.types.json_marshal.go.tmpl} | 0 6 files changed, 11 insertions(+), 11 deletions(-) rename internal/jennies/golang/veneers/{disjunction_of_structs.types.json_marshal.go.tmpl => disjunction_of_refs.types.json_marshal.go.tmpl} (100%) diff --git a/internal/ast/compiler/disjunctions.go b/internal/ast/compiler/disjunctions.go index 18dd5b7c0..79f9e956f 100644 --- a/internal/ast/compiler/disjunctions.go +++ b/internal/ast/compiler/disjunctions.go @@ -173,7 +173,7 @@ func (pass *DisjunctionToType) processDisjunction(file *ast.File, def ast.Disjun return ast.Type{}, err } - structType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfStructs] = newDisjunctionDef + structType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfRefs] = newDisjunctionDef } pass.newObjects[newTypeName] = ast.Object{ diff --git a/internal/ast/compiler/disjunctions_test.go b/internal/ast/compiler/disjunctions_test.go index 9eb148675..fb08addf3 100644 --- a/internal/ast/compiler/disjunctions_test.go +++ b/internal/ast/compiler/disjunctions_test.go @@ -277,7 +277,7 @@ func TestDisjunctionToType_WithDisjunctionOfRefs_AsAnObject_NoDiscriminatorMetad "OtherStruct": "other-struct", "SomeStruct": "some-struct", } - disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfStructs] = disjunctionTypeWithDiscriminatorMeta + disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfRefs] = disjunctionTypeWithDiscriminatorMeta expectedObjects := []ast.Object{ ast.NewObject("ADisjunctionOfRefs", ast.NewRef("SomeStructOrOtherStruct")), @@ -330,7 +330,7 @@ func TestDisjunctionToType_WithDisjunctionOfRefs_AsAnObject_WithDiscriminatorFie "OtherStruct": "other-kind", "SomeStruct": "some-kind", } - disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfStructs] = disjunctionTypeWithDiscriminatorMeta + disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfRefs] = disjunctionTypeWithDiscriminatorMeta expectedObjects := []ast.Object{ ast.NewObject("ADisjunctionOfRefs", ast.NewRef("SomeStructOrOtherStruct")), @@ -385,7 +385,7 @@ func TestDisjunctionToType_WithDisjunctionOfRefs_AsAnObject_WithDiscriminatorFie "OtherStruct": "other-kind", "SomeStruct": "some-kind", } - disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfStructs] = disjunctionTypeWithDiscriminatorMeta + disjunctionStructType.Struct.Hint[ast.HintDiscriminatedDisjunctionOfRefs] = disjunctionTypeWithDiscriminatorMeta expectedObjects := []ast.Object{ ast.NewObject("ADisjunctionOfRefs", ast.NewRef("SomeStructOrOtherStruct")), diff --git a/internal/ast/hints.go b/internal/ast/hints.go index d4851b538..5efba143f 100644 --- a/internal/ast/hints.go +++ b/internal/ast/hints.go @@ -8,9 +8,9 @@ const ( // original definition of which is associated to this hint. HintDisjunctionOfScalars JennyHint = "disjunction_of_scalars" - // HintDiscriminatedDisjunctionOfStructs indicates that the struct was + // HintDiscriminatedDisjunctionOfRefs indicates that the struct was // previously represented in the IR by a disjunction of a fixed list of // references to structs, the original definition of which is associated // to this hint. - HintDiscriminatedDisjunctionOfStructs JennyHint = "disjunction_of_structs" + HintDiscriminatedDisjunctionOfRefs JennyHint = "disjunction_of_refs" ) diff --git a/internal/ast/types.go b/internal/ast/types.go index 9760c0319..4e36216ef 100644 --- a/internal/ast/types.go +++ b/internal/ast/types.go @@ -271,9 +271,9 @@ func (types Types) NonNullTypes() Types { type DisjunctionType struct { Branches Types - // If the branches are structs, some languages will need extra context to - // be able to distinguish between them. Golang, for example, doesn't support - // sum types (disjunctions of fixed types). + // If the branches are references to structs, some languages will need + // extra context to be able to distinguish between them. Golang, for + // example, doesn't support sum types (disjunctions of fixed types). // To emulate sum types for these languages, we need a way to // discriminate against every possible type. // diff --git a/internal/jennies/golang/rawtypes.go b/internal/jennies/golang/rawtypes.go index 494a1316e..336bd2d01 100644 --- a/internal/jennies/golang/rawtypes.go +++ b/internal/jennies/golang/rawtypes.go @@ -127,8 +127,8 @@ func (jenny RawTypes) jsonMarshalVeneer(def ast.Object) (string, error) { }) } - if hintVal, ok := structType.Hint[ast.HintDiscriminatedDisjunctionOfStructs]; ok { - return jenny.renderVeneerTemplate("disjunction_of_structs.types.json_marshal.go.tmpl", map[string]any{ + if hintVal, ok := structType.Hint[ast.HintDiscriminatedDisjunctionOfRefs]; ok { + return jenny.renderVeneerTemplate("disjunction_of_refs.types.json_marshal.go.tmpl", map[string]any{ "def": def, "hint": hintVal, }) diff --git a/internal/jennies/golang/veneers/disjunction_of_structs.types.json_marshal.go.tmpl b/internal/jennies/golang/veneers/disjunction_of_refs.types.json_marshal.go.tmpl similarity index 100% rename from internal/jennies/golang/veneers/disjunction_of_structs.types.json_marshal.go.tmpl rename to internal/jennies/golang/veneers/disjunction_of_refs.types.json_marshal.go.tmpl