#591 Flux: View menu in NavBar for .fan files doesn't show

KevinKelley Sun 10 May 2009

I'm not getting the right-click View menu for Fan files in Flux. I think it's to do with fwt::Menu not taking a with block; if I make the change below the menu works fine.

diff -r e4753211474a -r 8bb52d1e99c2 src/flux/flux/fan/Resource.fan
--- a/src/flux/flux/fan/Resource.fan	Sat May 09 10:54:08 2009 -0400
+++ b/src/flux/flux/fan/Resource.fan	Sun May 10 10:07:56 2009 -0500
@@ -103,7 +103,10 @@
   **
   virtual Menu? popup(Frame? frame, Event? event)
   {
--    return Menu { viewsMenu(frame, event) }
+    //return Menu { viewsMenu(frame, event) }
+    menu := Menu()
+    menu.add(viewsMenu(frame, event))
+    return menu
   }

qualidafial Sun 10 May 2009

In the original code, the it-block needs a trailing comma to be redirected to add.

andy Mon 11 May 2009

Promoted to ticket #591 and assigned to andy

andy Mon 11 May 2009

Ticket resolved in 1.0.42

Yep, just needed a trailing comma.

jodastephen Mon 11 May 2009

I think this bug suggests that the trailing comma is too easily missed out and is a language design flaw.

brian Mon 11 May 2009

I think this bug suggests that the trailing comma is too easily missed out and is a language design flaw.

I don't necessarily think that - it is more of a porting problem in that we had a large code base written before the comma.

qualidafial Mon 11 May 2009

I agree with Stephen. I've been thinking of ways we might catch this at the compiler. For example, there should be at least one expression in the it-block that references it--otherwise the compiler should probably emit a warning, maybe even an error.

KevinKelley Mon 11 May 2009

Smalltalks usually overload the , operator as an add method on Collection classes, and (sometimes) as a creation method on Object that creates and returns a list.

Like:

class List {
  List commaOperator(Obj o) { this.add(o); return this }
}

class Obj {
  List commaOperator(Obj o) { return [this, o] }
}

Obj[] aList := "item1" , "item2"
aList = aList , "item3"

Similar thing is done with the @ operator in class Magnitude, to create a Point by sending @aNum to another number (Magnitude is base class for numbers). So you can do:

pt := 3@4          // Num '@' returns Point
pt3d := 3@4@5      // Point '@' returns Point3D

which is pretty.

You can even generalize this to method parameters; type the method as taking a List, and use the comma operator to collect the parameters to be sent to the method. How far Fan ought to go in that direction, I don't know. Mostly I think we're in the right place; but this thing with trailing commas for add is surely awkward and not in the spirit.

brian Mon 11 May 2009

I agree with Stephen. I've been thinking of ways we might catch this at the compiler.

The compiler does typically catch it because it doesn't allow many expressions to be used a stand-alone statement. For example this is a compiler error since a constructor not assigned to anything isn't a valid statement:

Foo { Bar() }

That actually tends to catch a lot of these errors - in fact that is mostly how I ported the existing code base, the compiler caught a large percentage of those errors. Where things slipped thru was in factory methods. But I think in practice even those would rarely happen because they are obvious and easily caught as soon as you test the code.

Login or Signup to reply.