Skip to content
Open
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
13 changes: 8 additions & 5 deletions skiplang/cli/src/usage.sk
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ private fun usageOptions(options: Sequence<Cli.Arg>): String {
| _ -> ` --${arg.name}`
};
optFlags = arg match {
| Cli.ValuedArg{_value_name} ->
| Cli.ValuedArg{_value_name => value_name} ->
if (arg._repeatable) {
`${baseOptFlags} [<${_value_name}>]`
`${baseOptFlags} [<${value_name}>]`
} else {
`${baseOptFlags} <${_value_name}>`
`${baseOptFlags} <${value_name}>`
}
| _ if (arg._repeatable) -> `${baseOptFlags}...`
| _ -> baseOptFlags
Expand Down Expand Up @@ -144,8 +144,11 @@ fun usage(
values = cmd._args.filterMap(
(arg ->
(arg match {
| ValuedArg{_value_name, _value_about} if (_value_about.size() > 0) ->
Some((_value_name, _value_about))
| ValuedArg{
_value_name => value_name,
_value_about => value_about,
} if (value_about.size() > 0) ->
Some((value_name, value_about))
| _ -> None()
})),
);
Expand Down
8 changes: 4 additions & 4 deletions skiplang/compiler/src/convertTree.sk
Original file line number Diff line number Diff line change
Expand Up @@ -1383,27 +1383,27 @@ class Converter{file: FileCache.InputSource} {
range,
SkipAst.Pat_type(
SkipAst.Tid_object(SkipAst.Tclass((range, "Success"))),
Some(Positional(Array[(range, SkipAst.Pat_var((range, "__x")))])),
Some(Positional(Array[(range, SkipAst.Pat_var((range, "!x")))])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this now using "!x" as an identifier? surprising that we allow that! Or is this conversion pass already downstream of where that gets checked?

SkipAst.Complete(),
),
),
],
None(),
(range, SkipAst.Var((range, "__x"))),
(range, SkipAst.Var((range, "!x"))),
);
early_return_branch = (
List[
(
range,
SkipAst.Pat_type(
SkipAst.Tid_object(SkipAst.Tclass((range, "Failure"))),
Some(Positional(Array[(range, SkipAst.Pat_var((range, "__x")))])),
Some(Positional(Array[(range, SkipAst.Pat_var((range, "!x")))])),
SkipAst.Complete(),
),
),
],
None(),
(range, SkipAst.Return((range, SkipAst.Var((range, "__x"))))),
(range, SkipAst.Return((range, SkipAst.Var((range, "!x"))))),
);

SkipAst.Match(
Expand Down
8 changes: 4 additions & 4 deletions skiplang/compiler/src/skipNaming.sk
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ fun pattern_bindings(acc: UMap<void>, pat: A.Pattern): UMap<void> {
}
}

// TODO consider !name.i1.startsWith("_")
fun bind_pattern_name(acc: UMap<void>, name: A.Name): UMap<void> {
if (name.i1 != "_") acc.add(name, void) else acc
if (!name.i1.startsWith("_")) acc.add(name, void) else acc
}

fun bind_pattern_params(
Expand Down Expand Up @@ -940,14 +939,15 @@ fun check_locals_pattern(bound: Bound, pat: N.Pattern): Bound {
| N.Pat_const _
| N.Pat_literal _ ->
bound
| N.Pat_var(var_name) -> bound.bind(var_name)
| N.Pat_var(var_name) ->
if (is_wildcard_name(var_name)) bound else bound.bind(var_name)
| N.Pat_type(_, obj_params, _) ->
obj_params match {
| None() -> bound
| Some(params) -> params.foldl(check_locals_pattern, bound)
}
| N.Pat_as(p, var_name) ->
!bound = bound.bind(var_name);
!bound = if (is_wildcard_name(var_name)) bound else bound.bind(var_name);
check_locals_pattern(bound, p)
}
}
Expand Down
2 changes: 1 addition & 1 deletion skiplang/compiler/src/skipOuterIstUtils.sk
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ fun binding_needs_ref(binding: O.BindingInfo): Bool {
}

fun is_underscore_binding(b: O.Binding): Bool {
b.name.id == "_"
b.name.id.startsWith("_")
}

/* parameters */
Expand Down
1 change: 1 addition & 0 deletions skiplang/compiler/tests/syntax/invalid/under_ident_3.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions skiplang/compiler/tests/syntax/invalid/under_ident_3.exp_err
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
File "tests/syntax/invalid/under_ident_3.sk", line 10, characters 7-8:
You cannot use a variable that starts with _
8 | | T1(_x, _y, _)
9 | | T2(_x, _y, _) ->
10 | _x + _y
| ^^
11 | }
18 changes: 18 additions & 0 deletions skiplang/compiler/tests/syntax/invalid/under_ident_3.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
base class T {
children =
| T1(x: Int, y: Int, z: Int)
| T2(x: Int, y: Int, z: String)

fun broken(): Int {
this match {
| T1(_x, _y, _)
| T2(_x, _y, _) ->
_x + _y
}
}
}

fun main(): void {
t2 = T2(1, 2, "three");
print_string(t2.broken().toString())
}
6 changes: 3 additions & 3 deletions skiplang/compiler/tests/syntax/invalid/under_ident_7.exp_err
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "tests/syntax/invalid/under_ident_7.sk", line 4, characters 11-11:
Unbound name: _
File "tests/syntax/invalid/under_ident_7.sk", line 4, characters 22-22:
You cannot use a variable that starts with _
2 | fun matcher(): T {
3 | this match {
4 | | Foo{_ => _} -> _
| ^
| ^
5 | }