tests: update tests

This commit is contained in:
2026-06-13 17:46:15 +02:00
parent 6048ee020f
commit b0af01d906
7 changed files with 517 additions and 276 deletions

View File

@@ -13,6 +13,20 @@
]
},
"message": "Cannot assign str to variable 'c' of type int"
},
{
"type": "Error",
"location": {
"start": [
9,
4
],
"end": [
9,
9
]
},
"message": "Undefined operation __add__ between bool and bool"
}
],
"judgments": [
@@ -158,9 +172,7 @@
"name": "d"
}
},
"type": {
"name": "int"
}
"type": {}
},
{
"location": {

View File

@@ -264,7 +264,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -328,7 +327,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -410,7 +408,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -509,7 +506,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -609,7 +605,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -725,7 +720,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -842,7 +836,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -924,7 +917,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -1006,7 +998,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -1123,7 +1114,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -1240,7 +1230,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,
@@ -1357,7 +1346,6 @@
"name": "foo"
},
"type": {
"name": "foo",
"pos_args": [
{
"pos": 0,

View File

@@ -3,12 +3,12 @@ type Second = float
type MeterPerSecond = float
extend Meter {
op __add__(Meter) -> Meter
op __sub__(Meter) -> Meter
op __truediv__(Second) -> MeterPerSecond
def __add__: fn(Meter, /) -> Meter
def __sub__: fn(Meter, /) -> Meter
def __truediv__: fn(Second, /) -> MeterPerSecond
}
extend Second {
op __add__(Second) -> Second
op __sub__(Second) -> Second
def __add__: fn(Second, /) -> Second
def __sub__: fn(Second, /) -> Second
}

View File

@@ -9,4 +9,4 @@ def maximum(a: float, b: float):
v3 = maximum(v1, v2)
v3 = v1 + v2
v3 = v2 + v1

View File

@@ -63,7 +63,6 @@
"name": "maximum"
},
"type": {
"name": "maximum",
"pos_args": [],
"args": [
{
@@ -149,10 +148,10 @@
},
"expr": {
"_type": "VariableExpr",
"name": "v1"
"name": "v2"
},
"type": {
"name": "int"
"name": "float"
}
},
{
@@ -162,10 +161,10 @@
},
"expr": {
"_type": "VariableExpr",
"name": "v2"
"name": "v1"
},
"type": {
"name": "float"
"name": "int"
}
},
{
@@ -177,12 +176,12 @@
"_type": "BinaryExpr",
"left": {
"_type": "VariableExpr",
"name": "v1"
"name": "v2"
},
"operator": "+",
"right": {
"_type": "VariableExpr",
"name": "v2"
"name": "v1"
}
},
"type": {

View File

@@ -10,8 +10,8 @@ type Difference[T] = T
// Complex custom type, containing two values accessible through properties
type GeoLocation = {
lat: Latitude
lon: Longitude
prop lat: Latitude
prop lon: Longitude
}
// Define operations on our custom type
@@ -19,23 +19,23 @@ extend GeoLocation {
// This type is compatible with the `-` operation with another GeoLocation
// i.e. you can subtract a GeoLocation from another GeoLocation, resulting
// in a Difference of GeoLocations
op __sub__(GeoLocation) -> Difference[GeoLocation]
def __sub__: fn(GeoLocation, /) -> Difference[GeoLocation]
}
// For complex generics, you need to specify how the genericity the properties
// are handled
type Difference[GeoLocation] = {
lat: Difference[Latitude]
lon: Difference[Longitude]
prop lat: Difference[Latitude]
prop lon: Difference[Longitude]
}
// Simple operation defined on our custom types
extend Latitude {
op __sub__(Latitude) -> Difference[Latitude]
def __sub__: fn(Latitude, /) -> Difference[Latitude]
}
extend Longitude {
op __sub__(Longitude) -> Difference[Longitude]
def __sub__: fn(Longitude, /) -> Difference[Longitude]
}
// Predefined custom predicates that can be referenced in other definitions
@@ -45,13 +45,13 @@ predicate Equatorial(loc: GeoLocation) = (-10 <= loc.lat <= 10)
predicate Arctic(loc: GeoLocation) = (loc.lat >= 66)
type Person = {
name: str
prop name: str
// Property with an inline constraint
age: Optional[int where (0 <= _ < 150)]
prop age: Optional[int where (0 <= _ < 150)]
// Property referencing a predicate
height: float where StrictlyPositive
prop height: float where StrictlyPositive
home: GeoLocation
prop home: GeoLocation
}

File diff suppressed because it is too large Load Diff