Internal error - decl not semanted

Monkey Forums/Monkey Programming/Internal error - decl not semanted

c.k.(Posted 2013) [#1]
What does this error message mean, and how do I fix it?

Here's where it occurs:

[monkeycode]
currPattern[Current_Pattern - 4] += String(t.bttnID)
[/monkeycode]


c.k.(Posted 2013) [#2]
Hi, c.k.!

Using this works:

[monkeycode]
currPattern[Current_Pattern - 4] = currPattern[Current_Pattern - 4] + String(t.bttnID)
[/monkeycode]
I wonder why.


ziggy(Posted 2013) [#3]
It looks like a compiler bug to me. If you can't use the += operator on array items, it should at last provide a proper compiler error


c.k.(Posted 2013) [#4]
Before I turned currPattern into an array, it worked fine.

[monkeycode]
Field currPattern:String = ""
currPattern += t.bttnID
[/monkeycode]


ziggy(Posted 2013) [#5]
I've placed a bug report here: http://www.monkeycoder.co.nz/Community/posts.php?topic=4767


Dima(Posted 2013) [#6]
edit: never mind this post, I didn't realize it was an array of strings and ones again rushed a reply.

strings are immutable, indexing string as array returns integer, string[index] is a read only property. use ToChars() and FromChars() if you would like to manipulate strings as integer array. ziggy is correct in that it should throw a compiler error.

Function Main()
	Local s$ = "hi"
	s[0] = "H"   ' throws compile error
End



muddy_shoes(Posted 2013) [#7]
The example isn't attempting to manipulate a string via an array index. It's replacing a string stored at an index in an array of strings.


Dima(Posted 2013) [#8]
edit: oops, I see what you mean muddy - it's an array of strings...

muddy_shoes, please elaborate - I'm under the impression that immutable strings are arrays of integers and by indexing a string we can read the ascii value of that array.


Samah(Posted 2013) [#9]
@Dima: ...I'm under the impression that immutable strings are arrays of integers...

Strings are implemented by the host language in whatever native format it expects. They are not arrays of integers (not in Monkey-speak, anyway).


c.k.(Posted 2013) [#10]
It's appending to a string found inside an array.

Oddly enough, this is basically what I (thought I) was doing:

[monkeycode]
Function Main()
Local my:String[] =["", ""]
For Local t:Int = 0 Until 5
Print t
my[1 - 1] += t
Next
Print my[0]

For Local t:Int = 0 Until 5
Print t
my[1 - 0] += t
Next

Print my[1]

End Function
[/monkeycode]

But that works fine (apparently)! Hmmmmm...


Samah(Posted 2013) [#11]
As I explained here, it's fine with constant values. "1-1" and "1-0" are automatically converted to "0" and "1" respectively by the compiler, so they're technically still constants.


c.k.(Posted 2013) [#12]
Ah, OK. Thanks, Samah.