Skip to content

Commit ddc1529

Browse files
committed
allow assigning components to a value, by checking the components type
1 parent d578e13 commit ddc1529

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

src/java/boa/types/BoaArray.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ public BoaArray(final BoaType boaType) {
4444
/** {@inheritDoc} */
4545
@Override
4646
public boolean assigns(final BoaType that) {
47-
// if that is a function, check its return type
47+
// if that is a function, check the return type
4848
if (that instanceof BoaFunction)
4949
return this.assigns(((BoaFunction) that).getType());
5050

51+
// if that is a component, check the type
52+
if (that instanceof BoaName)
53+
return this.assigns(((BoaName) that).getType());
54+
5155
if (that instanceof BoaTuple) {
5256
for (BoaType t : ((BoaTuple) that).getTypes())
5357
if (!this.type.assigns(t))

src/java/boa/types/BoaMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public BoaMap(final BoaType valueType, final BoaType indexType) {
5151
/** {@inheritDoc} */
5252
@Override
5353
public boolean assigns(final BoaType that) {
54-
// if that is a function, check the return value
54+
// if that is a function, check the return type
5555
if (that instanceof BoaFunction)
5656
return this.assigns(((BoaFunction) that).getType());
5757

58+
// if that is a component, check the type
59+
if (that instanceof BoaName)
60+
return this.assigns(((BoaName) that).getType());
61+
5862
// otherwise, if that is not a map, forget it
5963
if (!(that instanceof BoaMap))
6064
return false;

src/java/boa/types/BoaProtoList.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ public BoaProtoList(final BoaType boaType) {
4747
/** {@inheritDoc} */
4848
@Override
4949
public boolean assigns(final BoaType that) {
50-
// if that is a function, check its return type
50+
// if that is a function, check the return type
5151
if (that instanceof BoaFunction)
5252
return this.assigns(((BoaFunction) that).getType());
5353

54+
// if that is a component, check the type
55+
if (that instanceof BoaName)
56+
return this.assigns(((BoaName) that).getType());
57+
5458
if (that instanceof BoaTuple) {
5559
for (BoaType t : ((BoaTuple) that).getTypes())
5660
if (!this.type.assigns(t))

src/java/boa/types/BoaScalar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public boolean assigns(final BoaType that) {
2929
if (that instanceof BoaFunction)
3030
return this.assigns(((BoaFunction) that).getType());
3131

32-
// otherwise, if it's not a scalar, forget it
33-
if (!(that instanceof BoaScalar))
34-
return false;
32+
// if that is a component, check the type
33+
if (that instanceof BoaName)
34+
return this.assigns(((BoaName) that).getType());
3535

3636
// check that the classes match
3737
return this.getClass().equals(that.getClass());

src/java/boa/types/BoaSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ public BoaSet(final BoaType boaType) {
4545
/** {@inheritDoc} */
4646
@Override
4747
public boolean assigns(final BoaType that) {
48-
// if that is a function, check the return value
48+
// if that is a function, check the return type
4949
if (that instanceof BoaFunction)
5050
return this.assigns(((BoaFunction) that).getType());
5151

52+
// if that is a component, check the type
53+
if (that instanceof BoaName)
54+
return this.assigns(((BoaName) that).getType());
55+
5256
// otherwise, if that is not a set, forget it
5357
if (!(that instanceof BoaSet))
5458
return false;

src/java/boa/types/BoaStack.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ public BoaStack(final BoaType boaType) {
4545
/** {@inheritDoc} */
4646
@Override
4747
public boolean assigns(final BoaType that) {
48-
// if that is a function, check the return value
48+
// if that is a function, check the return type
4949
if (that instanceof BoaFunction)
5050
return this.assigns(((BoaFunction) that).getType());
5151

52+
// if that is a component, check the type
53+
if (that instanceof BoaName)
54+
return this.assigns(((BoaName) that).getType());
55+
5256
// otherwise, if that is not a stack, forget it
5357
if (!(that instanceof BoaStack))
5458
return false;

src/java/boa/types/BoaTuple.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ protected BoaTuple(final List<BoaType> members, final Map<String, Integer> names
5757
/** {@inheritDoc} */
5858
@Override
5959
public boolean assigns(final BoaType that) {
60+
// if that is a function, check the return type
6061
if (that instanceof BoaFunction)
6162
return this.assigns(((BoaFunction) that).getType());
6263

64+
// if that is a component, check the type
65+
if (that instanceof BoaName)
66+
return this.assigns(((BoaName) that).getType());
67+
6368
if (that instanceof BoaArray) {
6469
BoaType type = ((BoaArray) that).getType();
6570
if (type instanceof BoaName)

test/typecheck/component-names.boa

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
o1: output top(5)[i1: int][i2: int] of v: int weight s: float;
2+
o2: output top(5)[i1: int][i2: int] of v: int weight s: float;
3+
4+
s: set of i: int;
5+
st: stack of i: int;
6+
arr: array of i: int;
7+
m: map[k: string] of v: float;
8+
9+
v1: map[foo: string] of map[foo1: Expression] of set of foo2: string;
10+
v2: map[foo: string] of map[foo1: Expression] of set of foo2: string;
11+

0 commit comments

Comments
 (0)