Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: Handle gracefuly multi-varargs
This solve a very borderline issue when a signature contains more than one vararg parameter. They are still refused in the common case but can occurs when multiple initializers are combined into a single constructor. The implemented semantic is the following: * vararg parameters remains varag * if more than one vararg parameter exists in a signature, then the signature does not accepts additional arguments, it means that each vararg is associated to a single argument (a discarded alternative was to only keep the first/last parameter as the main vararg one) * the associated argument can be either a single value, of a reverse vararg with an ellipsis. ~~~nit class A fun x(i: Int...) is autoinit do end fun y(j: Int...) is autoinit do end end var a a = new A(10, 20) # OK: i=[10], j=[20] a = new A(10, 11, 20) # Refused a = new A([10, 11]..., 20) # OK: i=[10, 11], j=[20] a = new A([10, 11]..., [20, 21, 22]...) # OK: i=[10, 11], j=[20, 21, 22] a = new A([10, 11], [20, 21, 22]) # Refused but a hint is given that `...` may be missing ~~~ Pull-Request: #1825 Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
- Loading branch information
Showing
9 changed files
with
147 additions
and
39 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
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
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,51 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import array | ||
|
||
class A | ||
fun x(ints: Int...) is autoinit do | ||
for i in ints do | ||
'X'.output | ||
i.output | ||
end | ||
'\n'.output | ||
end | ||
end | ||
|
||
class B | ||
super A | ||
fun y(objs: Object...) is autoinit do | ||
for i in objs do | ||
'Y'.output | ||
i.output | ||
end | ||
'\n'.output | ||
end | ||
end | ||
|
||
var x | ||
|
||
#alt1#x = new A | ||
x = new A(1) | ||
x = new A(10, 20) | ||
x = new A([100, 200, 300]...) | ||
|
||
#aly1#x = new B(1) | ||
x = new B(1, 2) | ||
#alt1#x = new B(1, 2, 3) | ||
#alt1#x = new B([10, 20], 33) | ||
x = new B([10, 11]..., 20) | ||
x = new B(10, [20, 21]...) | ||
x = new B([10, 11]..., [20, 21, 23]...) |
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,30 @@ | ||
X1 | ||
|
||
X10 | ||
X20 | ||
|
||
X100 | ||
X200 | ||
X300 | ||
|
||
X1 | ||
|
||
Y2 | ||
|
||
X10 | ||
X11 | ||
|
||
Y20 | ||
|
||
X10 | ||
|
||
Y20 | ||
Y21 | ||
|
||
X10 | ||
X11 | ||
|
||
Y20 | ||
Y21 | ||
Y23 | ||
|
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,3 @@ | ||
alt/base_vararg_mult_alt1.nit:40,5--7: Error: expected at least 1 argument(s) for `init(ints: Int...)`; got 0. See introduction at `core::Object::init`. | ||
alt/base_vararg_mult_alt1.nit:47,5--7: Error: expected 2 argument(s) for `init(ints: Int..., objs: Object...)`; got 3. See introduction at `core::Object::init`. | ||
alt/base_vararg_mult_alt1.nit:48,11--18: Type Error: expected `Int`, got `Array[Int]`. Is an ellipsis `...` missing on the argument? |