Skip to content

Commit a5faf14

Browse files
committed
[Dana]Fix powint-erroneous.dana
Add actual semantic error in powint-erroneous.dana and highlighted it with a comment.
1 parent cf6b311 commit a5faf14

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
def main
22

33
def powint: base as int, exp as int, mod as int, result as ref int
4-
5-
base := base % mod
4+
65
var temp is int
76

87
if exp < 1:
98
result := 1
9+
elif exp = 0:
10+
result := 1
1011
else:
11-
if exp % 2 = 0:
12-
powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
13-
result := (temp * temp) % mod
14-
else:
15-
powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
16-
result := (base * temp) % mod
12+
powint: base, exp / 2, mod, temp
13+
14+
if exp % 2 = 0:
15+
result := (temp * temp) % mod
16+
else:
17+
result := (base * temp * temp) % mod
18+
19+
writeString: temp # SEMANTIC ERROR: Calling writeString (expects byte[]) with an int argument (temp)
1720

1821
var b is int
1922
var e is int
2023
var m is int
2124
var res is int
2225

26+
writeString: "Enter base: "
2327
b := readInteger()
28+
writeString: "Enter exponent: "
2429
e := readInteger()
30+
writeString: "Enter modulus: "
2531
m := readInteger()
2632

2733
powint: b, e, m, res
2834

35+
writeString: "Result: "
2936
writeInteger: res
3037
writeString: "\n"

0 commit comments

Comments
 (0)