Skip to content

Commit 40f8f56

Browse files
committedMar 21, 2023
Check that dot operators are not applied to nullable types.
1 parent 668170e commit 40f8f56

16 files changed

+33
-30
lines changed
 

‎benchmarks/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ priority_queue: priority_queue.cc
77
$(CPP) $(CCFLAGS) -o priority_queue priority_queue.cc
88

99
fh: fh.rn
10-
rune -U -O fh.rn
10+
../rune -U -O fh.rn
1111

1212
binary_trees_cc: binary_trees.cc
1313
clang++ -O3 binary_trees.cc -o binary_trees_cc

‎benchmarks/fh.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for i in range(10u32) {
4848
do {
4949
element = root.popHeapElement()
5050
} while !isnull(element) {
51-
totalHash = hashValues(totalHash, element.cost)
51+
totalHash = hashValues(totalHash, element!.cost)
5252
}
5353
println totalHash
5454
}

‎bind/bindexpr.c

+3
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,9 @@ static bool bindDotExpression(deBlock scopeBlock, deExpression expression) {
16051605
deDatatypeType type = deDatatypeGetType(datatype);
16061606
deBlock classBlock;
16071607
if (type == DE_TYPE_CLASS) {
1608+
if (deDatatypeNullable(datatype)) {
1609+
error(expression, "Cannot use dot operator on nullable type.");
1610+
}
16081611
classBlock = deClassGetSubBlock(deDatatypeGetClass(datatype));
16091612
} else if (type == DE_TYPE_NULL) {
16101613
blockOnNullResolution(scopeBlock, expression);

‎bootstrap/database/block.rn

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ class Block(self, line: Line) {
114114

115115
func owningBlock(self) -> Block? {
116116
if !isnull(self.owningFunction) {
117-
return self.owningFunction.block
117+
return self.owningFunction!.block
118118
} else if !isnull(self.owningStatement) {
119-
return self.owningStatement.block
119+
return self.owningStatement!.block
120120
// TODO: Comment back in when we port class.
121121
// } else if !isnull(self.owningClass) {
122122
// return self.owningClass.tclass.function.block
@@ -150,8 +150,8 @@ unittest {
150150
use value
151151
use expr
152152

153-
rootBlock = getRoot().block
154-
rootLine = rootBlock.line
153+
rootBlock = getRootBlock()
154+
rootLine = rootBlock.line!
155155
rootFilepath = rootLine.filepath!
156156

157157
func createEmptyBlock() -> Block {

‎bootstrap/database/function.rn

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Function(self, owningBlock: Block?, type: FuncType, sym: Sym,
187187
// |childFunction| will be called with no parameters.
188188
func appendFunctionCall(self, childFunction: Function) -> Statement {
189189
ident = childFunction.firstIdent
190-
pathExpr = ident.createPathExpr()
190+
pathExpr = ident!.createPathExpr()
191191
text = "%s()\n" % childFunction.name()
192192
block = self.subBlock!
193193
line = Line(block.line.filepath!, text, 0u32)
@@ -224,7 +224,7 @@ class Function(self, owningBlock: Block?, type: FuncType, sym: Sym,
224224
// Append a call statement to the module initialization function in the root block.
225225
func insertModuleInitializationCall(moduleFunc: Function) {
226226
ident = moduleFunc.firstIdent
227-
pathExpr = ident.createPathExpr()
227+
pathExpr = ident!.createPathExpr()
228228
block = moduleFunc.subBlock
229229
text = "%s()\n" % moduleFunc.name()
230230
line = Line(block.line.filepath!, text, 0u32)
@@ -330,5 +330,5 @@ unittest insertModuleInitializationCallTest {
330330
function2 = createEmptyFunction(getRoot().block!, "module2")
331331
insertModuleInitializationCall(function1)
332332
insertModuleInitializationCall(function2)
333-
getRoot().block.dump()
333+
getRootBlock().dump()
334334
}

‎bootstrap/database/ident.rn

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class Ident(self, block: Block, object: Function | Variable, sym: Sym, objLine:
9292
// Return the line of the identifier.
9393
func line(self) -> Line {
9494
if !isnull(self.function) {
95-
return self.function.line
95+
return self.function!.line
9696
}
97-
return self.variable.line
97+
return self.variable!.line!
9898
}
9999

100100
// Find an identifier from the path Expr.

‎bootstrap/database/value.rn

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Value(self: Value, value: string | bool | Int | Uint | Bigint | Float | Sy
9696
return "%ff%u" % (self.floatVal, self.width)
9797
}
9898
case DatatypeType.Int, DatatypeType.Uint {
99-
return self.intVal.toString()
99+
return self.intVal!.toString()
100100
}
101101
case DatatypeType.Sym {
102102
return self.symVal.name
@@ -134,7 +134,7 @@ unittest valueTypesTest {
134134
c = Value(true)
135135
d = Value(3.1415927f32)
136136
e = Value(Sym.new("test"))
137-
println a.intVal.toStringInBase(16u32)
137+
println a.intVal!.toStringInBase(16u32)
138138
println b
139139
println c
140140
println d

‎builtin/dict.rn

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class Dict(self, <keyType>, <valueType>) {
3434
if isnull(entry) {
3535
throw "Key not found in dictionary"
3636
}
37-
self.removeEntry(entry)
37+
self.removeEntry(entry!)
3838
}
3939

4040
func find(self, key) {
4141
entry = self.findEntry(key)
4242
if isnull(entry) {
4343
throw "Key not found in dictionary"
4444
}
45-
return entry.value
45+
return entry!.value
4646
}
4747

4848
operator [] (dict: Dict, key) {

‎builtin/doublylinked.rn

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
4848
if isnull(prevChild) {
4949
self.insert$labelB$B(child)
5050
} else {
51-
nextChild = prevChild.next$A$labelB$B
51+
nextChild = prevChild!.next$A$labelB$B
5252
if isnull(nextChild) {
5353
self.append$labelB$B(child)
5454
} else {
@@ -124,21 +124,21 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
124124
}
125125

126126
iterator $labelB$pluralB(self) {
127-
for child = self.first$labelB$B, !isnull(child), child = child.next$A$labelB$B {
127+
for child = self.first$labelB$B, !isnull(child), child = child!.next$A$labelB$B {
128128
yield child!
129129
}
130130
}
131131

132132
iterator reverse$labelB$pluralB(self) {
133-
for child = self.last$labelB$B, !isnull(child), child = child.prev$A$labelB$B {
133+
for child = self.last$labelB$B, !isnull(child), child = child!.prev$A$labelB$B {
134134
yield child!
135135
}
136136
}
137137

138138
iterator safe$labelB$pluralB(self) {
139139
child = self.first$labelB$B
140140
while !isnull(child) {
141-
next$A$labelB$B = child.next$A$labelB$B
141+
next$A$labelB$B = child!.next$A$labelB$B
142142
yield child!
143143
child = next$A$labelB$B
144144
}
@@ -147,7 +147,7 @@ generator DoublyLinked(A: Class, B: Class, cascadeDelete:bool = false,
147147
iterator safeReverse$labelB$pluralB(self) {
148148
child = self.last$labelB$B
149149
while !isnull(child) {
150-
prev$A$labelB$B = child.prev$A$labelB$B
150+
prev$A$labelB$B = child!.prev$A$labelB$B
151151
yield child!
152152
child = prev$A$labelB$B
153153
}

‎builtin/heapq.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Heapq(self, <valueType>) {
3232
if isnull(element) {
3333
throw "Heapq underflow"
3434
}
35-
return element.value
35+
return element!.value
3636
}
3737

3838
func empty(self) {

‎builtin/taillinked.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ generator TailLinked(A: Class, B: Class, cascadeDelete:bool = false,
126126
}
127127

128128
iterator $labelB$pluralB(self) {
129-
for child = self.first$labelB$B, !isnull(child), child = child.next$A$labelB$B {
129+
for child = self.first$labelB$B, !isnull(child), child = child!.next$A$labelB$B {
130130
yield child!
131131
}
132132
}

‎database/util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void dePrintIndentStr(deString string) {
5252

5353
// Report an error, but do not exit.
5454
static void reportError(deLine line, char *buf) {
55-
printf("**********");
55+
printf("********** Error\n");
5656
if (line != deLineNull) {
5757
deFilepath filepath = deLineGetFilepath(line);
5858
utAssert(filepath != deFilepathNull);

‎tests/classheapsort.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ root.pushElement(Element("Alice", 32))
3737
do {
3838
element = root.popElement()
3939
} while !isnull(element) {
40-
println element
40+
println element!
4141
}

‎tests/heapqlisttest.rn

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ for i in range(list.length()) {
5454
do {
5555
b = a.popB()
5656
} while !isnull(b) {
57-
println "popped B ", b.cost
58-
b.destroy()
57+
println "popped B ", b!.cost
58+
b!.destroy()
5959
}
6060
do {
6161
c = a.popC()
6262
} while !isnull(c) {
63-
println "popped C ", c.cost
64-
c.destroy()
63+
println "popped C ", c!.cost
64+
c!.destroy()
6565
}
6666
for i in range(list.length()) {
6767
B(a, list[i])

‎tests/localassign.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Foo(self) {
1616
}
1717

1818
func asdf() {
19-
println bar
19+
println bar!
2020
}
2121

2222
foo = null(Foo)

‎tests/testnull.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class Bar(self) {
2020

2121
b = null(Bar)
2222
b = Bar()
23-
b.bar()
23+
b!.bar()

0 commit comments

Comments
 (0)
Please sign in to comment.