Forums

Cobra internal error with mixin

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 with mixin

Postby fraya » Fri Apr 17, 2015 4:54 pm

Cobra svn:3116 (post 0.9.6) / 2015-04-17 on Mono 3.12.1 CLR v4.0.30319 on Unix 3.19.3.1
OpenSuse tumbleweed
Linux 3.19.3-1-desktop #1 SMP PREEMPT Thu Mar 26 17:34:34 UTC 2015 (f10e7fc) x86_64 x86_64 x86_64 GNU/Linux

I have the following code:
Code: Select all
use System.Diagnostics


mixin CommandLineTool
   """
   To access tools via command invocation.
   """

   var _commandEnvironmentVariables = Dictionary<of String, String>()
   var _commandError = false
   var _exception as Exception?
   var _commandOutput = ''
   var _exitCode = 0
   var _lastCommand as String?

   get commandError from var as bool
      """
      Error produced after running a command
      """

   get exception from var as Exception?
      """
      Exception saved in last command run.
      """

   get commandOutput from var as String
      """
      Output of the last command run.
      """

   get exitCode from var as int
        """
       Value of exit code of the last command when it terminated.
       """
       
   get lastCommand from var as String?
      """
      Last command executed
      """

   # Environment variables added before run a command

   def commandEnvironmentVariable(key as String) as String
      require
         key.length
      body
         return _commandEnvironmentVariables[key]

   def setCommandEnvironmentVariable(name as String, value as String)
      """
      Set an environment variable that will be set before run
      the command. Once set it will be used every time a command
      is run until it is removed.
      """
      require
         name.length
      ensure
         .commandEnvironmentVariable(name) == value
      body
         _commandEnvironmentVariables[name] = value

   def cleanEnvironmentVariables
      """
      Remove environment variables
      """
      _commandEnvironmentVariables = Dictionary<of String, String>()

   def runCommand(command as String, args as String)
      """
      Run the tool with args as parameters
      """
      require
         command.length
         args.length
      body
         p = Process()

         for key, value in _commandEnvironmentVariables
            p.startInfo.environmentVariables[key] = value
         
         p.startInfo.fileName  = command
         p.startInfo.arguments = args
      
         try
            _commandOutput = p.runAndCaptureAllOutput.trim
            _exitCode = p.exitCode
            _commandError = false
            _lastCommand = command + ' ' + args
         catch ex as Exception
            _commandOutput = ''
            _commandError  = true
            _exception = ex

class Foo
   adds CommandLineTool

   cue init
      base.init

   def main is shared
      f = Foo()


when I compile I have this error:
Code: Select all
fraya@:~/Downloads> cobra mixin1.cobra
error: COBRA INTERNAL ERROR / InvalidCastException / Cannot cast from source type to destination type.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


same with cobra -verbose
Code: Select all
fraya@:~/Downloads> cobra -verbose mixin1.cobra
Cobra Command Line svn:3116 (post 0.9.6) / 2015-04-17
Copyright (C) 2003-2015 by Cobra Language LLC.

OS Version:   Unix 3.19.3.1
CLR Platform: Mono
CLR Version:  4.0.30319.17020
Current Directory: /home/fraya/Downloads
Current Exe: /usr/local/cobra/Cobra-svn-3116/bin/cobra.exe
Option Dictionary:
    verbosity: 1
    back-end: 'none'
    contracts: 'inline'
    copy-core: false
    correct-source: Set<of String>['none']
    debug: '1'
    debugging-tips: true
    embed-run-time: false
    embed-version: 'compiler-version'
    include-asserts: true
    include-nil-checks: true
    include-tests: true
    include-traces: true
    native-compiler: 'auto'
    number: 'decimal'
    test-runner: 'Cobra.Core.CobraCore.runAppTests'
    testify-results: 'r-testify.text'
    library-directory: List<of String>[]
Paths:
    mixin1.cobra
Phase: Binding Cobra run-time library
Adding reference to Cobra.Core.dll
Adding reference to System.Core.dll
Phase: Reading libraries
Reading assembly:  mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
              at:  /usr/lib/mono/4.5/mscorlib.dll
Reading assembly:  System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
              at:  /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
Loading reference: Cobra.Core.dll
Reading assembly:  Cobra.Core, Version=0.0.3116.1, Culture=neutral, PublicKeyToken=0a4783a5c7c9616e
              at:  /usr/local/cobra/Cobra-svn-3116/bin/Cobra.Core.dll
Loading reference: System.Core.dll
Reading assembly:  System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
              at:  /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
Phase: Parsing source code
Phase: Binding use directives
Phase: Binding inheritance
Phase: Binding interface
Phase: Binding mixins
error: COBRA INTERNAL ERROR / InvalidCastException / Cannot cast from source type to destination type.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


Same problem with Cobra 0.9.6

Any help?, thanks
fraya
 
Posts: 7

Re: Cobra internal error with mixin

Postby thriwkin » Thu Apr 23, 2015 8:39 pm

The Cobra program is correct, but the cobra.exe (of Cobra svn:3116) cannot compile a try-catch statement in a method or property of a mixin.

This little program contains the 3 possible forms of a try-catch statement.
It reproduces the failure:

mixin Mixin1

def m1
try
pass
catch
pass

def m2
try
pass
catch Exception
pass

def m3
try
pass
catch ex as Exception
CobraCore.noOp(ex)

class A adds Mixin1
pass

class P
def main is shared
pass


This file contains a minimal patch for this issue:
Mixin-catch-stmt.patch
(2.04 KiB) Downloaded 2291 times

When applied, to the source code of Cobra svn:3116, the test program above compiles and runs, and -testify does not show any regression in the test suite of the compiler.

Could someone try it out, with his private Cobra source?

How to try it out, in a simple way:
1. Precondition: you have downloaded the Cobra source code, for example into the directory "CobraSvnWorkspace" (how to do this is described here).
2. Download the patch file into this CobraSvnWorkspace.
3. Apply the patch with some SVN client or edit the source files by hand.
4. Run the installation program again (in CobraSvnWorkspace/Source/bin/install-from-workspace).
5. Compile and run the above test program.
On my computer it works now, and the CommandLineTool program as well.
thriwkin
 
Posts: 26

Re: Cobra internal error with mixin

Postby Charles » Mon Apr 27, 2015 8:07 pm

Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Cobra internal error with mixin

Postby thriwkin » Tue Apr 28, 2015 6:54 am

Thanks for the feedback.
thriwkin
 
Posts: 26


Return to Discussion

Who is online

Users browsing this forum: No registered users and 9 guests