Skip to content

Commit

Permalink
Changed error message for invalid type parameters to include Subtract
Browse files Browse the repository at this point in the history
Summary:
+ Problem: The error message for failing to give arithmetic type operators types that are a subtype of int does not include `Subtract`.
+ Background: In the previous diff, we implemented the `Subtract` type operator. When it fails (and is given arguments that are not a subtype of int), a particular error message displays, which is hard-coded to include `Add`, `Multiply`, and `Divide`, but not `Subtract`.
+ Solution: This diff just makes `Subtract` included in that message.

Reviewed By: pradeep90

Differential Revision: D30049950

fbshipit-source-id: d4b17b32d83428a02f36094cff73e87365d37b12
  • Loading branch information
Brandon Wu authored and facebook-github-bot committed Aug 11, 2021
1 parent 6a3d99c commit e40e8c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions source/analysis/analysisError.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,9 @@ let rec messages ~concise ~signature location kind =
[
Format.asprintf
"Type parameter `%a` violates constraints on \
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Divide`. Add & \
Multiply & Divide only accept type variables with a bound that's a subtype of int."
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Subtract`/`pyre_extensions.Divide`. \
Add & Multiply & Subtract & Divide only accept type variables with a bound that's a \
subtype of int."
pp_type
actual;
]
Expand Down
20 changes: 12 additions & 8 deletions source/analysis/test/integration/annotationTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1853,14 +1853,17 @@ let test_check_typevar_arithmetic context =
|}
[
"Invalid type parameters [24]: Type parameter `Variable[A]` violates constraints on \
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Divide`. Add & Multiply & \
Divide only accept type variables with a bound that's a subtype of int.";
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Subtract`/`pyre_extensions.Divide`. \
Add & Multiply & Subtract & Divide only accept type variables with a bound that's a subtype \
of int.";
"Invalid type parameters [24]: Type parameter `Variable[A]` violates constraints on \
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Divide`. Add & Multiply & \
Divide only accept type variables with a bound that's a subtype of int.";
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Subtract`/`pyre_extensions.Divide`. \
Add & Multiply & Subtract & Divide only accept type variables with a bound that's a subtype \
of int.";
"Invalid type parameters [24]: Type parameter `Variable[A]` violates constraints on \
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Divide`. Add & Multiply & \
Divide only accept type variables with a bound that's a subtype of int.";
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Subtract`/`pyre_extensions.Divide`. \
Add & Multiply & Subtract & Divide only accept type variables with a bound that's a subtype \
of int.";
];
assert_type_errors
{|
Expand Down Expand Up @@ -3424,8 +3427,9 @@ let test_check_subtract context =
|}
[
"Invalid type parameters [24]: Type parameter `Variable[A]` violates constraints on \
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Divide`. Add & Multiply & \
Divide only accept type variables with a bound that's a subtype of int.";
`pyre_extensions.Add`/`pyre_extensions.Multiply`/`pyre_extensions.Subtract`/`pyre_extensions.Divide`. \
Add & Multiply & Subtract & Divide only accept type variables with a bound that's a subtype \
of int.";
];
assert_default_type_errors
{|
Expand Down

0 comments on commit e40e8c2

Please sign in to comment.