From d72cdd40329207af482950cb8a004da10d5a8126 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 27 Aug 2023 14:47:43 -0400 Subject: [PATCH 1/2] Fixes anonymous givens Problem ------- Currently given uses `_function_constructor`, which expects an identifier. This doesn't work for anonymous given definition that has function-ish things like `using` parameters. Solution -------- Create a new `_given_constructor` node with an optional name. --- corpus/definitions.txt | 65 ++++++++++++++++++++++++++++++------------ grammar.js | 17 ++++++++++- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/corpus/definitions.txt b/corpus/definitions.txt index a9ba63be1..f57109f83 100644 --- a/corpus/definitions.txt +++ b/corpus/definitions.txt @@ -1219,9 +1219,6 @@ object A: given foo(using ev: Foo) : Foo = ev - given [T: Ordering]: Ordering[List[T]] with - def x = () - given Context = ctx given Context[T] = ctx @@ -1229,6 +1226,14 @@ object A: given Foo[Int] = case n => "123" + given (using a: Int): Int = a + + given [A: Foo]: Foo[List[A]] with + def x = () + + given [A](using Foo[A]): Foo[List[A]] with + def x = () + -------------------------------------------------------------------------------- (compilation_unit @@ -1309,8 +1314,31 @@ object A: (type_identifier) (identifier)) (given_definition - (identifier - (MISSING _alpha_identifier)) + (type_identifier) + (identifier)) + (given_definition + (generic_type + (type_identifier) + (type_arguments + (type_identifier))) + (identifier)) + (given_definition + (generic_type + (type_identifier) + (type_arguments + (type_identifier))) + (indented_cases + (case_clause + (identifier) + (string)))) + (given_definition + (parameters + (parameter + (identifier) + (type_identifier))) + (type_identifier) + (identifier)) + (given_definition (type_parameters (identifier) (context_bound @@ -1327,23 +1355,24 @@ object A: (identifier) (unit)))) (given_definition - (type_identifier) - (identifier)) - (given_definition - (generic_type - (type_identifier) - (type_arguments - (type_identifier))) - (identifier)) - (given_definition + (type_parameters + (identifier)) + (parameters + (generic_type + (type_identifier) + (type_arguments + (type_identifier)))) (generic_type (type_identifier) (type_arguments - (type_identifier))) - (indented_cases - (case_clause + (generic_type + (type_identifier) + (type_arguments + (type_identifier))))) + (with_template_body + (function_definition (identifier) - (string))))))) + (unit))))))) ================================================================================ Top-level Definitions (Scala 3 syntax) diff --git a/grammar.js b/grammar.js index 1a525e83b..260074d00 100644 --- a/grammar.js +++ b/grammar.js @@ -70,6 +70,7 @@ module.exports = grammar({ [$.if_expression], [$.match_expression], [$._function_constructor, $._type_identifier], + [$._given_constructor, $._type_identifier], [$.instance_expression], // In case of: 'extension' _indent '{' 'case' operator_identifier 'if' operator_identifier • '=>' … // we treat `operator_identifier` as `simple_expression` @@ -583,7 +584,7 @@ module.exports = grammar({ repeat($.annotation), optional($.modifiers), "given", - optional(seq($._function_constructor, ":")), + optional($._given_constructor), choice( field("return_type", $._structural_instance), seq( @@ -595,6 +596,20 @@ module.exports = grammar({ ), ), + _given_constructor: $ => + prec.right( + seq( + field("name", optional($._identifier)), + field("type_parameters", optional($.type_parameters)), + field( + "parameters", + repeat(seq(optional($._automatic_semicolon), $.parameters)), + ), + optional($._automatic_semicolon), + ":", + ), + ), + /** * StructuralInstance ::= ConstrApp {'with' ConstrApp} ['with' WithTemplateBody] */ From 3c4276437a6704c389e5849154096f00e6269276 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 27 Aug 2023 15:40:10 -0400 Subject: [PATCH 2/2] Reduce the Dotty percentage to 83 --- script/smoke_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/smoke_test.sh b/script/smoke_test.sh index b8ced8e91..8e6fa08a6 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -4,7 +4,7 @@ SCALA_SCALA_LIBRARY_EXPECTED=100 SCALA_SCALA_COMPILER_EXPECTED=96 -DOTTY_COMPILER_EXPECTED=84 +DOTTY_COMPILER_EXPECTED=83 SYNTAX_COMPLEXITY_CEILING=1300 if [ ! -d "$SCALA_SCALA_DIR" ]; then