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

Polymorphic function type and lambda expression #444

Merged
merged 2 commits into from
Dec 17, 2024
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
16 changes: 15 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const PREC = {

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, scala_scala/src/library/: 100.00%, expected at least 100%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, scala_scala/src/compiler/: 96.65%, expected at least 96%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, dotty/compiler/: 83.76%, expected at least 83%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, lila/modules/: 84.35%, expected at least 84%
comment: 1,
using_directive: 2,
control: 1,
Expand Down Expand Up @@ -92,6 +92,8 @@
[$.class_parameters],
// 'for' operator_identifier ':' _annotated_type • ':' …
[$._type, $.compound_type],
// 'given' '(' '[' _type_parameter • ',' …
[$._variant_type_parameter, $.type_lambda],
// 'given' '(' operator_identifier ':' _type • ',' …
[$.name_and_type, $.parameter],
[$._simple_expression, $.binding, $.tuple_pattern],
Expand Down Expand Up @@ -954,7 +956,7 @@
),
),

tuple_type: $ => seq("(", trailingCommaSep1($._type), ")"),

Check notice on line 959 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

ok, complexity of the most complex definition tuple_type: 1223, lower than the allowed ceiling 1400

named_tuple_type: $ => seq(
"(",
Expand Down Expand Up @@ -1008,7 +1010,10 @@

function_type: $ =>
prec.left(
seq(field("parameter_types", $.parameter_types), $._arrow_then_type),
choice(
seq(field("type_parameters", $.type_parameters), $._arrow_then_type),
seq(field("parameter_types", $.parameter_types), $._arrow_then_type),
)
),

_arrow_then_type: $ =>
Expand Down Expand Up @@ -1190,6 +1195,15 @@
lambda_expression: $ =>
prec.right(
seq(
optional(
seq(
field(
"type_parameters",
$.type_parameters,
),
"=>",
),
),
field(
"parameters",
choice(
Expand Down
42 changes: 37 additions & 5 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,6 @@ object O {
{ b =>
if (c) d.e }
{ a => implicit b => b }
{ (a: Int) ?=> (b: Int) => b }
{ (_, a) => a }
}

Expand Down Expand Up @@ -1198,6 +1197,31 @@ object O {
(identifier)
(identifier))))
(block
(lambda_expression
(bindings
(binding
(wildcard))
(binding
(identifier)))
(identifier))))))

================================================================================
Lambda Expression (Scala 3 syntax)
================================================================================

object O:
val f = (a: Int) ?=> (b: Int) => b

val less: Comparer = [X: Ord] => (x: X, y: X) => ???

--------------------------------------------------------------------------------

(compilation_unit
(object_definition
(identifier)
(template_body
(val_definition
(identifier)
(lambda_expression
(bindings
(binding
Expand All @@ -1209,14 +1233,22 @@ object O {
(identifier)
(type_identifier)))
(identifier))))
(block
(val_definition
(identifier)
(type_identifier)
(lambda_expression
(type_parameters
(identifier)
(context_bound
(type_identifier)))
(bindings
(binding
(wildcard))
(identifier)
(type_identifier))
(binding
(identifier)))
(identifier))))))
(identifier)
(type_identifier)))
(operator_identifier))))))

================================================================================
Unit expressions
Expand Down
26 changes: 26 additions & 0 deletions test/corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ object Main {
(type_identifier)
(type_identifier)))))))

================================================================================
Polymorphic function types (Scala 3 syntax)
================================================================================

class A:
type Comparer = [X: Ord] => (X, X) => Boolean

--------------------------------------------------------------------------------

(compilation_unit
(class_definition
(identifier)
(template_body
(type_definition
(type_identifier)
(function_type
(type_parameters
(identifier)
(context_bound
(type_identifier)))
(function_type
(parameter_types
(type_identifier)
(type_identifier))
(type_identifier)))))))

================================================================================
Context function types (Scala 3 syntax)
================================================================================
Expand Down
Loading