mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-05-10 03:00:06 -04:00
Add fake hash and use it to compare functions and class instances
This commit is contained in:
12
inputs/failing/collidingClasses.ts
Normal file
12
inputs/failing/collidingClasses.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// //! test_output("foo")
|
||||
|
||||
export default () => {
|
||||
class X {
|
||||
foo = "foo";
|
||||
}
|
||||
|
||||
return new X().foo;
|
||||
};
|
||||
|
||||
// deno-lint-ignore no-unused-vars
|
||||
class X {}
|
||||
31
inputs/failing/compareClassInstancesWithEqualSources.ts
Normal file
31
inputs/failing/compareClassInstancesWithEqualSources.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
//! test_output(false)
|
||||
// Should be: true
|
||||
|
||||
// When functions (and therefore classes) have the same source (and references), they should compare
|
||||
// equal due to the content hash system. This isn't implemented yet - the content hash is just faked
|
||||
// using its location in the bytecode, which means you only get equal comparison when the functions
|
||||
// are referentially equal (inconsistent with value semantics).
|
||||
|
||||
export default () => {
|
||||
const a = new classes[0](1, 2);
|
||||
const b = new classes[1](1, 2);
|
||||
|
||||
return a === b;
|
||||
};
|
||||
|
||||
const classes = [
|
||||
class Point {
|
||||
constructor(public x: number, public y: number) {}
|
||||
|
||||
lenSq() {
|
||||
return this.x ** 2 + this.y ** 2;
|
||||
}
|
||||
},
|
||||
class Point {
|
||||
constructor(public x: number, public y: number) {}
|
||||
|
||||
lenSq() {
|
||||
return this.x ** 2 + this.y ** 2;
|
||||
}
|
||||
},
|
||||
];
|
||||
22
inputs/passing/compareFunctionsAndClasses.ts
Normal file
22
inputs/passing/compareFunctionsAndClasses.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
//! test_output([true,true,false,true])
|
||||
|
||||
export default () => {
|
||||
const a = new Point(1, 2);
|
||||
const b = new Point(1, 2);
|
||||
const c = new Point(1, 3);
|
||||
|
||||
return [
|
||||
a.lenSq === b.lenSq,
|
||||
a === b,
|
||||
a === c,
|
||||
c === c,
|
||||
];
|
||||
};
|
||||
|
||||
class Point {
|
||||
constructor(public x: number, public y: number) {}
|
||||
|
||||
lenSq() {
|
||||
return this.x ** 2 + this.y ** 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user