-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add defaultValue method on type intersection constraint
Summary: As title. The logic for computing the default value is straightforward - choose all possible default values that satisfy all constraints in the intersection. If there is more than one possible default, choose one in the specified precedence order. Reviewed By: jano Differential Revision: D64982596 fbshipit-source-id: 641f92cf51ce12c75b2fcc1393862486c8dafee1
- Loading branch information
1 parent
149ff37
commit 4acb057
Showing
5 changed files
with
186 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| HipHop for PHP | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#include "hphp/runtime/vm/type-constraint.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace HPHP { | ||
TEST(TypeChecks, TypeVar) { | ||
/* | ||
* Test the following types of type constraints | ||
* main: TypeConstraint{flags:TypeVar, type:Mixed, clsName:<null>, typeName:T} | ||
*/ | ||
auto const typeVar = TypeConstraint( | ||
AnnotType::Mixed, | ||
TypeConstraintFlags::TypeVar, | ||
LowStringPtr(StringData::MakeStatic("T")) | ||
); | ||
auto const tic = TypeIntersectionConstraint(std::vector<TypeConstraint>({typeVar})); | ||
EXPECT_EQ(KindOfNull, tic.defaultValue()->m_type); | ||
} | ||
|
||
TEST(TypeChecks, NullableString) { | ||
auto nullableString = TypeConstraint( | ||
AnnotType::String, | ||
(TypeConstraintFlags::Nullable | ||
| TypeConstraintFlags::Resolved | ||
| TypeConstraintFlags::DisplayNullable | ||
| TypeConstraintFlags::UpperBound), | ||
LowStringPtr(StringData::MakeStatic("HH\\string")) | ||
); | ||
auto const tic = TypeIntersectionConstraint(std::vector<TypeConstraint>({nullableString})); | ||
EXPECT_EQ(KindOfNull, tic.defaultValue()->m_type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters