Ticket #334 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Cobra Internal error if source file ends in comma separated expression

Reported by: hopscc Owned by: Chuck
Priority: major Milestone:
Component: Cobra Compiler Version: 0.9.4
Keywords: Cc:


Reported by Chasm
See  forum item

test program

class Program

   def main
      variable as int
      streamReader = StreamReader("Something.txt")

When looking for separators or terminators, CobraParser commaSepExpr handling does some .peek calls and immediately derefs the result.

If there is no token ( end of Stream) this gets a
NullReferenceException which generates a COBRA INTERNAL ERROR.

specific patch on its way pending testing but more generally
perhaps use of this this pattern


needs hardening...


comma-sep-intrnl-error.patch Download (1.9 KB) - added by hopscc 5 years ago.

Change History

Changed 5 years ago by hopscc

  • owner changed from hopscc to Chuck
  • status changed from new to assigned
  • version changed from 0.8.0 to 0.9.4

Fix and tests for this case.
Still need chk uses of above pattern.

Changed 5 years ago by hopscc

Changed 5 years ago by Charles

Just a couple minutes looking through the parser, and I find more cases of these including in _commaSepTypes, class declarations and dictionary literals.

I think the real solution is going to be to review every use of .peek. Also, to provide a .peekRequired which returns IToken (not IToken?) and throws an 'Unexpected end of source.' error if there are no more tokens.

Changed 5 years ago by hopscc

Yeah better hardening is pretty much my (100% fix) conclusion too...

Where would you then be calling .peek rather than .peekRequired ?

Looks likes theres only about 10 calls in CobraParser where .peek is expecting/checking for nil return/EoStream...

maybe simpler if .peek made unnilable and return a EoStream token at end of Tokens..
(then would get 'Unexpected EndOfStream.... anywhere stream unexpectedly stops
just from normal processing.) Change explicit nil checks to EoStream checks or whatever...

OTOH its not like these have cropped up much to date,
dont smack you when you're familiar with cobra coding/layout/program structure - just seem to occur occasionally as new users begin initial experimentation or something,
So we could just address them as we have been, as they occur on the assumption that they ones that show up then are the 'obvious' fracture points.

Is there any valid expectation that half a program should compile nicely???

OTOOH CobraInternal Error probably isnt best response...

Was thinking apply this specific fix for this specific report/situation - Open new
ticket for general unexpected EoToken Stream handling... (all others not yet reported).....

Changed 5 years ago by Charles

The big issue is that this comes up all the time in the IDE where the CobraParser? is invoked on half completed source code on a regular basis.

I was working on this today and came to your same conclusion--always provide an EOF token. I'm halfway through this now.

Changed 5 years ago by Charles

  • status changed from assigned to closed
  • resolution set to fixed

All fixed in changeset:3007 which introduces the EOF token.

Note: See TracTickets for help on using tickets.