Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ generated in the following situations:

### 2.0.5-dev

* [TRLC, LRM] Allow union types as tuple field types:
`tuple Ref { item [TypeA, TypeB] separator @ version Integer }` now
permits a tuple field to reference objects of any of the listed record types.



### 2.0.4
Expand Down
19 changes: 17 additions & 2 deletions documentation/TUTORIAL-TUPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@ Requirement potato {
}
```

Tuples can contain any kind of data, including other tuples; but it is
not possible to have array fields or create recursive tuples.
Tuples can contain any kind of data, including other tuples and union
types; but it is not possible to have array fields or create recursive
tuples.

A field in a tuple may also use the union type syntax to accept
references to any of several record types:

```
tuple LevelRef {
item [SystemRequirement, AssumedRequirement]
separator @
version Integer
}
```

This follows the same rules as union type fields on record types (see
[Advanced Types](TUTORIAL-ADVANCED-TYPES.md)).

## Syntactic sugar

Expand Down
5 changes: 3 additions & 2 deletions language-reference-manual/lrm.trlc
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ section "Type declarations" {
'}'

field_declaration ::=
described_name [ 'optional' ] qualified_name_FIELD_TYPE
described_name [ 'optional' ] ( qualified_name_FIELD_TYPE | union_type )

separator_declaration ::=
'separator' separator_symbol
Expand All @@ -544,7 +544,8 @@ section "Type declarations" {
Static_Semantics Tuple_Field_Types {
text = '''
A field type names any valid visible and complete
type. *(Specifically you may not have a recursive
type. This includes union types (see union_type).
*(Specifically you may not have a recursive
tuple reference.)*
'''
}
Expand Down
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-checks/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = s1 @ 0
^ union-type-in-tuple-checks/test.trlc:14: check error: version must be positive
Processed 1 model and 1 requirement file and found 1 error
2 changes: 2 additions & 0 deletions tests-system/union-type-in-tuple-checks/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union-type-in-tuple-checks/test.trlc:14:23: trlc check error: version must be positive
Processed 1 model and 1 requirement file and found 1 error
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-checks/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = s1 @ 0
^ union-type-in-tuple-checks/test.trlc:14: check error: version must be positive
Processed 1 model and 1 requirement file and found 1 error
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-checks/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = s1 @ 0
^ union-type-in-tuple-checks/test.trlc:14: check error: version must be positive
Processed 1 model and 1 requirement file and found 1 error
24 changes: 24 additions & 0 deletions tests-system/union-type-in-tuple-checks/test.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Test

type SystemReq {
description String
}

type AssumedReq {
rationale String
}

tuple LevelRef {
item [SystemReq, AssumedReq]
separator @
version Integer
}

checks LevelRef {
version > 0, error "version must be positive", version
}

type FeatReq {
description String
derived_from LevelRef
}
15 changes: 15 additions & 0 deletions tests-system/union-type-in-tuple-checks/test.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Test

SystemReq s1 {
description = "system req 1"
}

FeatReq f1 {
description = "ok"
derived_from = s1 @ 1
}

FeatReq f2 {
description = "bad version"
derived_from = s1 @ 0
}
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-checks/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LRM.Tuple_Field_Types
LRM.union_type
LRM.Evaluation_Of_Checks
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
item [TypeA, TypeB, TypeA]
^^^^^ union-type-in-tuple-duplicate/test.rsl:12: error: duplicate type TypeA in union
Processed 1 model and 1 requirement file and found 1 error
2 changes: 2 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union-type-in-tuple-duplicate/test.rsl:12:26: trlc error: duplicate type TypeA in union
Processed 1 model and 1 requirement file and found 1 error
4 changes: 4 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
item [TypeA, TypeB, TypeA]
^^^^^ union-type-in-tuple-duplicate/test.rsl:12: error: duplicate type TypeA in union
{}
Processed 1 model and 1 requirement file and found 1 error
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
item [TypeA, TypeB, TypeA]
^^^^^ union-type-in-tuple-duplicate/test.rsl:12: error: duplicate type TypeA in union
Processed 1 model and 1 requirement file and found 1 error
20 changes: 20 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/test.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Test

type TypeA {
a Integer
}

type TypeB {
b Integer
}

tuple BadRef {
item [TypeA, TypeB, TypeA]
separator @
version Integer
}

type Req {
description String
link BadRef
}
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple-duplicate/test.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package Test
2 changes: 2 additions & 0 deletions tests-system/union-type-in-tuple-duplicate/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LRM.Union_Type_No_Duplicates
LRM.Tuple_Field_Types
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple-no-separator/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
23 changes: 23 additions & 0 deletions tests-system/union-type-in-tuple-no-separator/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"alpha1": {
"a": "alpha"
},
"beta1": {
"b": "beta"
},
"r1": {
"description": "linked to alpha",
"parent": {
"item": "Test.alpha1",
"version": 1
}
},
"r2": {
"description": "linked to beta",
"parent": {
"item": "Test.beta1",
"version": 2
}
}
}
Processed 1 model and 1 requirement file and found no issues
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
19 changes: 19 additions & 0 deletions tests-system/union-type-in-tuple-no-separator/test.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Test

type AlphaReq {
a String
}

type BetaReq {
b String
}

tuple ReqRef {
item [AlphaReq, BetaReq]
version Integer
}

type Req {
description String
parent ReqRef
}
19 changes: 19 additions & 0 deletions tests-system/union-type-in-tuple-no-separator/test.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Test

AlphaReq alpha1 {
a = "alpha"
}

BetaReq beta1 {
b = "beta"
}

Req r1 {
description = "linked to alpha"
parent = (alpha1, 1)
}

Req r2 {
description = "linked to beta"
parent = (beta1, 2)
}
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-no-separator/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LRM.union_type
LRM.Tuple_Field_Types
LRM.Tuple_Generic_Form
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple-optional/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple-optional/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
30 changes: 30 additions & 0 deletions tests-system/union-type-in-tuple-optional/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"alpha": {
"a": "hello"
},
"beta": {
"b": "world"
},
"r1": {
"description": "with version",
"link": {
"ref": "Test.alpha",
"version": 1
}
},
"r2": {
"description": "with version",
"link": {
"ref": "Test.beta",
"version": 2
}
},
"r3": {
"description": "without version",
"link": {
"ref": "Test.alpha",
"version": null
}
}
}
Processed 1 model and 1 requirement file and found no issues
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple-optional/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
20 changes: 20 additions & 0 deletions tests-system/union-type-in-tuple-optional/test.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Test

type TypeA {
a String
}

type TypeB {
b String
}

tuple OptRef {
ref [TypeA, TypeB]
separator @
version optional Integer
}

type Req {
description String
link OptRef
}
24 changes: 24 additions & 0 deletions tests-system/union-type-in-tuple-optional/test.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Test

TypeA alpha {
a = "hello"
}

TypeB beta {
b = "world"
}

Req r1 {
description = "with version"
link = alpha @ 1
}

Req r2 {
description = "with version"
link = beta @ 2
}

Req r3 {
description = "without version"
link = alpha
}
4 changes: 4 additions & 0 deletions tests-system/union-type-in-tuple-optional/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LRM.Tuple_Field_Types
LRM.union_type
LRM.Tuple_Optional_Fields
LRM.Tuple_Optional_Requires_Separators
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = other1 @ 1
^^^^^^ union-type-in-tuple-wrong-type/test.trlc:9: error: expected reference of type [SystemReq, AssumedSystemReq], but other1 is of type OtherReq
Processed 1 model and 1 requirement file and found 1 error
2 changes: 2 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union-type-in-tuple-wrong-type/test.trlc:9:18: trlc error: expected reference of type [SystemReq, AssumedSystemReq], but other1 is of type OtherReq
Processed 1 model and 1 requirement file and found 1 error
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = other1 @ 1
^^^^^^ union-type-in-tuple-wrong-type/test.trlc:9: error: expected reference of type [SystemReq, AssumedSystemReq], but other1 is of type OtherReq
Processed 1 model and 1 requirement file and found 1 error
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
derived_from = other1 @ 1
^^^^^^ union-type-in-tuple-wrong-type/test.trlc:9: error: expected reference of type [SystemReq, AssumedSystemReq], but other1 is of type OtherReq
Processed 1 model and 1 requirement file and found 1 error
24 changes: 24 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/test.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Test

type SystemReq {
description String
}

type AssumedSystemReq {
rationale String
}

type OtherReq {
text String
}

tuple SystemLevelReqId {
item [SystemReq, AssumedSystemReq]
separator @
version Integer
}

type FeatReq {
description String
derived_from SystemLevelReqId
}
10 changes: 10 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/test.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Test

OtherReq other1 {
text = "I am not a system req"
}

FeatReq bad {
description = "wrong type in union tuple field"
derived_from = other1 @ 1
}
3 changes: 3 additions & 0 deletions tests-system/union-type-in-tuple-wrong-type/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LRM.union_type
LRM.Tuple_Field_Types
LRM.References_To_Extensions
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
1 change: 1 addition & 0 deletions tests-system/union-type-in-tuple/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
Loading
Loading