@Test public void memberAccessFailsIfInterfaceDoesNotHaveSpecifiedMember() { InterfaceType interfaceType = new InterfaceType(fullyQualifiedName("shed", "example", "Brother")); context.add(declaration, unassignableValue(interfaceType)); context.addInfo( interfaceType, new ScalarTypeInfo(interfaces(), members("age", unassignableValue(CoreTypes.DOUBLE)))); MemberAccessNode memberAccess = Nodes.member(reference, "height"); TypeResult<ValueInfo> result = inferValueInfo(memberAccess); assertThat(errorStrings(result), is(asList("No such member: height"))); }
@Test public void memberAccessIsAssignableIfMemberIsAssignable() { InterfaceType interfaceType = new InterfaceType(fullyQualifiedName("shed", "example", "Brother")); context.add(declaration, unassignableValue(interfaceType)); context.addInfo( interfaceType, new ScalarTypeInfo(interfaces(), members("age", assignableValue(CoreTypes.DOUBLE)))); MemberAccessNode memberAccess = Nodes.member(reference, "age"); TypeResult<ValueInfo> result = inferValueInfo(memberAccess); assertThat(result, isSuccessWithValue(assignableValue(CoreTypes.DOUBLE))); }
@Test public void memberAccessFailsIfLeftHandExpressionIsNotScalarType() { Type type = Types.newUnknown(); context.add(declaration, unassignableValue(type)); MemberAccessNode memberAccess = Nodes.member(reference, "height"); TypeResult<ValueInfo> result = inferValueInfo(memberAccess); assertThat(result, isFailureWithErrors(new NotScalarTypeError(type))); }