my_basic icon indicating copy to clipboard operation
my_basic copied to clipboard

Dict item not printed

Open lllucius opened this issue 7 years ago • 2 comments

When a var is defined as a dict() in a class, printing a value from it can print the variable type followed by an error. Here's some sample code:

class request
    var headers = dict()
    var cookies = dict()

    def sendheaders(s)
        print get(headers, s) + chr(10)
    enddef

    def sendbody(s)
    enddef

    def sendstatus(s)
    enddef

endclass

d = dict()
d("testing") = "123"
print "1: " + d("testing") + chr(10)
print "2: " + get(d, "testing") + chr(10)
print d("testing") + chr(10)

req = new(request)
req.headers("testing") = "123"

h = req.headers

print "3: " + h("testing") + chr(10)
print "4: " + get(h, "testing") + chr(10)
print h("testing") + chr(10)
print "5: " + req.headers("testing") + chr(10)
print "6: " + get(req.headers, "testing") + chr(10)

' This fails with:
'
' DICT
' Error:
'     Ln 34, Col 17
'     Code 30, Abort Code 3
'     Message: Comma or semicolon expected.
print req.headers("testing") + chr(10)

Running this produces:

1: 123
2: 123
123
3: 123
4: 123
123
5: 123
6: 123
DICT
Error:
    Ln 42, Col 17
    Code 30, Abort Code 3
    Message: Comma or semicolon expected.

lllucius avatar Mar 12 '18 01:03 lllucius

Temporarily use print get(req.headers, "testing") + chr(10) instead. I'll refactor the PRINT statement at some point.

paladin-t avatar Mar 12 '18 09:03 paladin-t

Sounds good.

lllucius avatar Mar 12 '18 14:03 lllucius