Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests to resolve previous bugs #22100

Merged
merged 5 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/arrays/intents/in/defaultValueWithInIntent.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// test from https://github.com/chapel-lang/chapel/issues/11424
var emptyArray: [1..0] string;

proc f(in x: [] string = emptyArray) {
writeln(x.size);
}

f(['f']);
1 change: 1 addition & 0 deletions test/arrays/intents/in/defaultValueWithInIntent.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
21 changes: 21 additions & 0 deletions test/classes/deinitializers/owned-with-deinit.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// modified from https://github.com/chapel-lang/chapel/issues/12973
// Basically a singly linked list.
class A {
var x: int;
var next: owned A?;

proc deinit() {
while next {
next = next!.next;
}
}
}

proc test(type T) {
var x = new T(1);
var y = new T(2, x);
var z = new T(3, y);
writeln(z);
}

test(owned A);
1 change: 1 addition & 0 deletions test/classes/deinitializers/owned-with-deinit.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{x = 3, next = {x = 2, next = {x = 1, next = nil}}}
14 changes: 14 additions & 0 deletions test/classes/delete-free/shared/shared-in-map-list.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// modified from https://github.com/chapel-lang/chapel/issues/14713
use Map;
use List;

class Node { }

var children: map(string, shared Node?);
var n = new shared Node();
children.add('key', n);
writeln(children);

var childrenList: list(shared Node?);
childrenList.append(n);
writeln(childrenList);
2 changes: 2 additions & 0 deletions test/classes/delete-free/shared/shared-in-map-list.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{key: {}}
[{}]
33 changes: 33 additions & 0 deletions test/classes/errors/newWithoutParen.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// modified from https://github.com/chapel-lang/chapel/issues/13201
// removed R1, as it does not work today due to other reasons and is not
// central to demonstrating this issue

class C {
var x: int = 0;
}

class D {
type T;
var x: T;
}

record R2 {
type T;
var x: T;

proc postinit() {
// expect: false
writeln(test1());
}
proc test1(): bool {
x = new T; // should not compile due to this
return x == nil;
}
}

proc main() {
var c2 = new R2(owned C?);
var d2 = new R2(owned D(int)?);

writeln("This code should not compile.");
}
1 change: 1 addition & 0 deletions test/classes/errors/newWithoutParen.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
newWithoutParen.chpl:23: syntax error: 'new' expression is missing its argument list
14 changes: 14 additions & 0 deletions test/classes/fields/type-resolve-array-field.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// modified from https://github.com/chapel-lang/chapel/issues/11421
class C {
var dom = {1..4};
var arr: [dom] real = 0.0;
}

var data: [1..2] real;

operator +(c1: owned C , c2: owned C) {
return c1;
}

var c = new owned C();
writeln(c.arr);
1 change: 1 addition & 0 deletions test/classes/fields/type-resolve-array-field.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0 0.0 0.0 0.0
9 changes: 9 additions & 0 deletions test/functions/lambda/lambdaCapturing.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// test from https://github.com/chapel-lang/chapel/issues/5544
proc times2(f) {
return 2*f();
}
proc test(k : int) {
var func = lambda() { return k;};
writeln(times2(func));
}
test(2);
3 changes: 3 additions & 0 deletions test/functions/lambda/lambdaCapturing.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lambdaCapturing.chpl:5: In function 'test':
lambdaCapturing.chpl:6: error: cannot capture lambda because it refers to outer variables
lambdaCapturing.chpl:6: note: such as 'k', here
31 changes: 31 additions & 0 deletions test/library/standard/Map/getBorrowFromFunc.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// modified from https://github.com/chapel-lang/chapel/issues/14370
use Map;

class C {
var x: int;
}

var m: map(string, shared C);

// original test used `this` accessor
// which is invalid for non-default initializable classes on an empty slot
// correctly throws an error in this case
// m["hi"] = new shared C(42);

m.add("hi", new shared C(42));

proc foo1(): borrowed C {
return m["hi"].borrow();
}
proc foo2(): borrowed C {
return m["hi"];
}

{
var elm = foo1();
writeln(elm, " ", elm.type:string);
}
{
var elm = foo2();
writeln(elm, " ", elm.type:string);
}
2 changes: 2 additions & 0 deletions test/library/standard/Map/getBorrowFromFunc.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{x = 42} borrowed C
{x = 42} borrowed C