Wiki

Ticket #217 (closed defect: wontfix)

Opened 8 years ago

Last modified 8 years ago

Something with not having a type on a get not being caught by the compiler.

Reported by: nevdelap Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

These are fine...

class Program

	def main
		print "a" + .thing

	def thing as char
		return c'b'
class Program

	def main
		print "a" + .thing

	get thing as char
		return c'b'

test.cobra(4): error: For "print" arg 1: Cannot mix types String and char for arithmetic.

This is fine...

class Program

	def main
		print "a" + .thing

	def thing
		return c'b'

test.cobra(4): error: For "print" arg 1: Cannot mix types String and void for arithmetic.
test.cobra(7): error: Cannot return char because "thing" is not declared to return anything.

But this compiles and throws at run...

class Program

	def main
		print "a" + .thing

	get thing
		return c'b'

Unhandled Exception: Cobra.Lang.UnknownMemberException?: obj='a', name='op_Addition or op_Addition_String_Char', type=System.String

Change History

Changed 8 years ago by nevdelap

I realized it is just returning it as a dynamic and the UnknownMemberException? probably the correct behavior.

Changed 8 years ago by nevdelap

Now I've realized it's coming back as a char not a dynamic, so maybe the compiler could have done something at compile time?

Changed 8 years ago by Chuck

  • status changed from new to closed
  • resolution set to wontfix

The behavior is correct. In the case of "def thing" the missing return type implies "no return type" or "void" so the + expression is clearly invalid (not to mention the error about returning a value in such a method). In the case of a property, however, the return type is inferred as "dynamic". Also, any errors regarding dynamic are delayed until run-time where the dynamically treated values and member access will either succeed or throw an exception.

Note: See TracTickets for help on using tickets.