Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Object addTrait should require at least one argument.

This reduces confusion about the behavior of "Foo addTrait".
If someone really wants to add nil as a trait to Foo,
it should be done explicitly.

Reviewed by jer.
  • Loading branch information...
commit 615152203980852600cdc96546e221752cf10641 1 parent e23b786
soc soc authored
2  libs/iovm/io/A0_Object.io
View
@@ -1,5 +1,7 @@
//doc Object addTrait Takes another object, whose slots will be copied into the receiver. Optionally takes a second argument, a Map object containing string -> string pairs, holding conflicting slot names and names to rename them to. I.e., if you have two objects A and B, both have a slot named foo, you issue A addTrait(B, Map clone atPut("foo", "newFoo")) the value of B foo will be placed in A newFoo.
Object addTrait := method(obj,
+ if(call message arguments size == 0,
+ Exception raise("addTrait requires at least one argument"))
resolutions := call evalArgAt(1)
if(resolutions isNil, resolutions = Map clone)
4 libs/iovm/tests/correctness/TraitsTest.io
View
@@ -21,4 +21,8 @@ TraitsTest := UnitTest clone do(
assertEquals(42, B fooFromA)
assertEquals(23, B foo)
)
+
+ testMissingArguments := method(
+ assertRaisesException(A addTrait)
+ )
)
Please sign in to comment.
Something went wrong with that request. Please try again.