Wiki

Ticket #74 (closed defect: fixed)

Opened 16 years ago

Last modified 15 years ago

Cannot pass dynamic values to initializers

Reported by: Chuck Owned by: eric.sellon
Priority: major Milestone: Cobra 0.9
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

The following code gives false compilation errors on the commented line:

class X

	def init
		.init(0, 'aoeu')
		
	def init(i as int, s as String)
		pass

	def foo(i as int, s as String)
		pass

	def main is shared
		a = 1 to dynamic
		b = 'aoeu' to dynamic
		x = X(a, b)  # test passing dynamic to an initializer
		x = X()
		x.foo(a, b)

Attachments

debug_help.patch Download (9.3 KB) - added by eric.sellon 15 years ago.
ticket74.patch Download (10.3 KB) - added by eric.sellon 15 years ago.

Change History

Changed 16 years ago by Chuck

  • milestone set to Cobra 0.9

Changed 15 years ago by eric.sellon

  • owner set to eric.sellon
  • status changed from new to assigned

Changed 15 years ago by eric.sellon

Patch file attached. Hope it helps.

Changed 15 years ago by Chuck

With this patch, PostCallExpr? now has a _computeBestOverload which is not quite the same as CallExpr?. Are the differences intentional or accidental? Do you think they could share one _computeBestOverload in a common base class? I ask because that's originally what I envisioned for this fix.

Otherwise, it seems we have two method overload resolution algorithms to maintain.

Let me know your thoughts.

Changed 15 years ago by Chuck

ping.

Would love to close this.

Changed 15 years ago by eric.sellon

Sorry. I've been busy lately and just today got time again to work on this. I figured a few hours would allow me to resolve this today, but I was wrong. So, I'm still working on getting all the tests passed with a single computeBestOverload function.

Changed 15 years ago by Chuck

Thanks for the update.

Changed 15 years ago by Chuck

Oh and if you want some IRC conversation, you have stick around for more than 2 minutes. Sometimes we're AFK for a period of time. :-)

Changed 15 years ago by eric.sellon

Changed 15 years ago by eric.sellon

If you use the attached debug help patch file and then try to compile 100-attributes.cobra, you'll see that symbolForName is returning something different on the second FallThroughException?. Please advise. Thank you.

Changed 15 years ago by Chuck

I'm looking tonight.

Changed 15 years ago by Chuck

I don't know if I have exactly the answer you were looking for, but I definitely have the info you need:

  • First, I noticed that the Param printed with didBindInt=false which is bad news. We should not be examining the interface of something (such as its .type) if it never went through the "bind interface" phase.
  • So I added require .bindInt to the MemberOverload.computeBestOverload method. I ran the compiler and this failed as I was expecting. Why?
  • In Expr.cobra there is the line possibleCalls = theClass.symbolForName('cue.init') which is the source of evil. Change it to .memberForName and everything is good.
  • .memberForName is more advanced than .symbolForName. It "preps" library types if they are unprepared due to not having done a .bindInh and .bindInt. It also includes extension methods. .memberForName is typically what you want.
  • I realize this is not obvious. Sorry for any confusion.
  • Also in the future, you may prefer trace x over print x for debugging.

Changed 15 years ago by eric.sellon

Great. Thanks for looking at it. I hope to try that out tonight.

Changed 15 years ago by eric.sellon

Changed 15 years ago by eric.sellon

Updated patch file. Should be good.

Changed 15 years ago by Chuck

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

Thanks. Applied in changeset:2167

One big item of feedback: in tests like 310-dynamic-init-params.cobra, use assert instead of print to validate the behavior. This way the testing is automatic.

See changeset:2167 for details on how I changed this.

Note: See TracTickets for help on using tickets.