Skip to content

Commit

Permalink
Skylark: Fix typing of structs
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=88546692
  • Loading branch information
laurentlb authored and hanwen committed Mar 16, 2015
1 parent 00d7223 commit e314e25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public static final class DictModule {}
.<Function, SkylarkType>builder()
.putAll(pureGlobalFunctions)
.put(list, SkylarkType.of(SkylarkList.class))
.put(struct, SkylarkType.of(ClassObject.class))
.put(struct, SkylarkType.of(ClassObject.SkylarkClassObject.class))
.put(hasattr, SkylarkType.BOOL)
.put(getattr, SkylarkType.UNKNOWN)
.put(set, SkylarkType.of(SkylarkNestedSet.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,23 @@ public void testStructAccessOfMethod() throws Exception {
"v = mock.function", MOCK_TYPES), env, "Object of type 'Mock' has no field 'function'");
}

@Test
public void testConditionalStructConcatenation() throws Exception {
MethodLibrary.setupMethodEnvironment(env);
exec(parseFileForSkylark(
"def func():\n"
+ " x = struct(a = 1, b = 2)\n"
+ " if True:\n"
+ " x += struct(c = 1, d = 2)\n"
+ " return x\n"
+ "x = func()\n"), env);
SkylarkClassObject x = (SkylarkClassObject) env.lookup("x");
assertEquals(1, x.getValue("a"));
assertEquals(2, x.getValue("b"));
assertEquals(1, x.getValue("c"));
assertEquals(2, x.getValue("d"));
}

@Test
public void testJavaFunctionReturnsMutableObject() throws Exception {
env.update("mock", new Mock());
Expand Down

0 comments on commit e314e25

Please sign in to comment.