UnknownMemberException thrown on local variable assignment
Posted: Wed Apr 23, 2014 2:08 am
Hi,
I came across Cobra just last week and thought it looked very interesting, especially liking the different ensure/require/test/body sections.
The language seems pretty easy to understand too, or so I think.
Having finally given up on Visual Studio yesterday, I went for Xamarin Studio which is a time-saver bar-none with the auto-completion (even if it has now stopped giving me real-time debug information for some reason).
However, I'm stuck on something incredibly stupid, and I'm feeling quite silly and lazy posting this, but I was wondering if anyone could help with the simplest of (bad) code segments there is (searches on this forum and Google reveal nothing).
I have a function which assigns a local variable the value of a class-level array element value.
Upon running this I get an UnknownMemberException pointing to the variable called "byte" (changing the name and/or type seems to make no difference).
The full exception report is here: https://dl.dropboxusercontent.com/u/4716604/cobra-exception-report.html
Plain exception text:
Help and humiliation are appreciated, thanks!
I came across Cobra just last week and thought it looked very interesting, especially liking the different ensure/require/test/body sections.
The language seems pretty easy to understand too, or so I think.
Having finally given up on Visual Studio yesterday, I went for Xamarin Studio which is a time-saver bar-none with the auto-completion (even if it has now stopped giving me real-time debug information for some reason).
However, I'm stuck on something incredibly stupid, and I'm feeling quite silly and lazy posting this, but I was wondering if anyone could help with the simplest of (bad) code segments there is (searches on this forum and Google reveal nothing).
I have a function which assigns a local variable the value of a class-level array element value.
Upon running this I get an UnknownMemberException pointing to the variable called "byte" (changing the name and/or type seems to make no difference).
"""
cobra --version
Cobra 0.9.6 on .NET CLR v4.0.30319 on Microsoft Windows NT 6.1.7601 Service Pack 1
"""
class Loader
var contents
var offset as int
def readByte as int
require
.contents <> nil
body
byte = .contents[.offset] # this is where Xamarin Studio points when the exception is thrown
.offset = .offset + 1
return byte
def load(filename as String)
.offset = 0
.contents = File.readAllBytes(filename)
if .readByte <> 65 # if it doesn't equal 'A', we have a problem
print "Invalid header\n"
class Program
def main
loader as Loader? = Loader()
loader.load('test.txt') # simply contains ABCDE
print "Done.\n"
The full exception report is here: https://dl.dropboxusercontent.com/u/4716604/cobra-exception-report.html
Plain exception text:
- Code: Select all
Unhandled Exception: Cobra.Core.UnknownMemberException: obj=Byte[][65 (Byte), 66 (Byte), 67 (Byte), 68 (Byte), 69 (Byte)], name='[]', type=System.Byte[]
at Cobra.Core.CobraImp.GetIndexerValue(Object obj, Object[] args)
at Loader.ReadByte() in d:\noshbar\cobra_problem_1\Program.cobra:line 16
at Loader.Load(String filename) in d:\noshbar\cobra_problem_1\Program.cobra:line 23
at Program.Main() in d:\noshbar\cobra_problem_1\Program.cobra:line 29
Help and humiliation are appreciated, thanks!