Forums

cobra internal error from MonoDevelop build

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

cobra internal error from MonoDevelop build

Postby kobi7 » Wed Jan 01, 2014 11:50 pm

Hi Charles, Are you ready for another round? ;-)
well, I am actually coding, and using the MonoDevelop addin.
Today I ran into this COBRA INTERNAL ERROR

I can send you the entire project, it's a small application that I hope will reach fruition. It's purpose is to suggest a garden arrangement based on companion planting. I'm in the 0.1 stages, but it's coming along nicely. Anyway I'm enjoying using cobra with the concise syntax, and learning new features all the time (why is the documentation hidden? ;-) )

so back from the excursion, here is the output from MonoDevelop xbuild.
Code: Select all
Building: SimpleGardenPlanner (Debug)

Build started 1/2/2014 8:41:58 AM.
__________________________________________________
Project "/home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/SimpleGardenPlanner.cobraproj" (Build target(s)):
   
   Target PrepareForBuild:
      Configuration: Debug Platform: AnyCPU
   
   Target GenerateSatelliteAssemblies:
   No input files were specified for target GenerateSatelliteAssemblies, skipping.
   
   Target CoreCompile:
      Tool /usr/local/bin/cobra execution started with arguments: -compile -back-end:none -clr-platform:AnyCPU -copy-core:no -correct-source:none -debug:1 -delay-sign:no -embed-run-time:yes -include-traces:yes -keep-intermediate-files:no -native-compiler:auto -number:decimal -out:/home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/obj/Debug/SimpleGardenPlanner.dll -target:lib -contracts:inline -include-asserts:yes -include-nil-checks:yes -include-tests:yes -optimize:no -reference:/home/kobi/WualaDrive/temperate/work_backup/Json.NET/Bin/Net40/Newtonsoft.Json.dll -native-compiler-arg:"/errorreport:none" /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/Dirt.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/Garden.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/IFieldItem.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/Plant.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/ManageGarden.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/Stone.cobra /home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/Code/Utils.cobra
/usr/lib/mono/xbuild/Cobra/Cobra.targets: error : error: COBRA INTERNAL ERROR / NullReferenceException / Object reference not set to an instance of an object
   Task "CobraCompiler" execution -- FAILED
   Done building target "CoreCompile" in project "/home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/SimpleGardenPlanner.cobraproj".-- FAILED
   
Done building project "/home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/SimpleGardenPlanner.cobraproj".-- FAILED

Build FAILED.
Errors:

/home/kobi/WualaDrive/temperate/work_backup/SimpleGardenPlanner/SimpleGardenPlanner.cobraproj (Build) ->
/usr/lib/mono/xbuild/Cobra/Cobra.targets (CoreCompile target) ->

   /usr/lib/mono/xbuild/Cobra/Cobra.targets: error : error: COBRA INTERNAL ERROR / NullReferenceException / Object reference not set to an instance of an object

    0 Warning(s)

---------------------- Done ----------------------

Build: 1 error, 0 warnings
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: cobra internal error from MonoDevelop build

Postby Charles » Thu Jan 02, 2014 2:38 am

The documentation is all over the wiki. And community editable. ;)

This is your offending line:
# Garden.cobra
var _plantSchema = JsonSchema.parse(Plant.plant_schema)

Specifically when Cobra tries to process "Plant.plant_schema", which is a shared method, it's not ready to do so yet. You should be able to work around with something like:
var _plantSchema as JsonSchema?
...
# inside a property or method:
_plantSchema ?= JsonSchema.parse(Plant.plant_schema)

...while I work on making this work or at least providing a good error message.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cobra internal error from MonoDevelop build

Postby Charles » Thu Jan 02, 2014 2:53 am

Well actually you could just put the initialization in cue.init:
class Garden

cue init...
base.init
_plantSchema = JsonSchema.parse(Plant.plant_schema)
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cobra internal error from MonoDevelop build

Postby Charles » Thu Jan 02, 2014 10:46 pm

This is fixed now in two ways:

1) You will get a proper error message:
Code: Select all
error: Cannot compile initialization expression at this point. Add an
explicit type to the `var` ("as <type>") or move to a `cue init` or change
the expression.


2) If you explicitly type the variable (by adding "as String", "as JsonSchema", etc) then it will work (as indicated in the new error message). This was not previously the case.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cobra internal error from MonoDevelop build

Postby kobi7 » Sat Jan 04, 2014 11:34 pm

hi Charles
my original intention with submitting the error reports about 'internal errors' was just to find where I typed something wrong, having the compiler state at least the line number where it balked. Then it would help find the problem on my own.
of course your fix is much better.

With regard to this use case, what I meant to do
is have a constant (or readonly) static variable that got its value just once, but during runtime.
something like
Code: Select all
private static decimal PI = getPiValueFromFile(@"/home/huge_pi.txt")

(what is the fixation some people have with pi is beyond me)
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: cobra internal error from MonoDevelop build

Postby Charles » Sun Jan 05, 2014 12:08 pm

IIRC your var was not shared/static. The equiv Cobra would be something like:
class A

shared

var pi = .readNumberFromFileNamed('/home/huge_pi.txt')

def readNumberFromFileNamed(fileName as String) as number
return decimal.parse(File.readAllText(fileName))

...hmm I don't think we have a "number.parse" but using `number` still reduces the number of places you would have to edit if you went with "@number float64" at some point.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cobra internal error from MonoDevelop build

Postby kobi7 » Mon Jan 06, 2014 4:28 am

is it possible to do something like this?
notice the "is shared" after var is initialized.
is it possible to write it as one line?

class A

shared
def readNumberFromFileNamed(fileName as String) as number
return decimal.parse(File.readAllText(fileName))

var pi = .readNumberFromFileNamed('/home/huge_pi.txt') is shared
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: cobra internal error from MonoDevelop build

Postby Charles » Mon Jan 06, 2014 4:36 am

Unfortunately, "is" is overloaded, which was a mistake on my part:
1) an operator for reference comparisons. `a is b` in Cobra means `a` and `b` refer to the same object (pointer equality)
2) a part of the syntax for declaring modifiers. `... is shared`

Community member Hopscc would like to resolve this in initialization expressions by preferring that the `is` be interpreted as 2. So far, I have resisted because at that point in the code you are in an expression.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cobra internal error from MonoDevelop build

Postby hopscc » Tue Jan 07, 2014 2:23 am

Actually no - tho that was the first approach.

The problem is that theres an ambiguity in the syntax with declaration with an initialisation expression (clause) and the isnames clause with the current ordering of the two of them.
The most recent patch/approach for this ( from ..ahem.. 4 years ago) changes the clause ordering and the ambiguity/problem goes away
( and it doesnt even cause any problems...)

from memory the order change is along the lines that kobi7 is asking about

(Its all detailed on ticket:34)

evidently the combination of an initialisation clause and isnames clause is rather uncommon...
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: cobra internal error from MonoDevelop build

Postby nerdzero » Tue Jan 07, 2014 7:57 am

hopscc wrote:evidently the combination of an initialisation clause and isnames clause is rather uncommon...

I think only because it doesn't work. I know I've tried it, saw it didn't work and then just moved on to a different approach.
nerdzero
 
Posts: 286
Location: Chicago, IL

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 105 guests