Skip to content

Commit 5f885e4

Browse files
committed
[[ LCB ]] Return type now 'returns ( <Type> | nothing )'.
The 'as <Type>' syntax to specify handler return types has been deprecated and 'returns <Type>' should be used instead. The 'as undefined' syntax to specify a void handler return type has been deprecated and 'returns nothing' should be used instead. The 'undefined' type has been deprecated as its only purpose was to specify a void handler return type.
1 parent aedb510 commit 5f885e4

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

libscript/src/script-module.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,10 @@ static void type_to_string(MCScriptModuleRef self, uindex_t p_type, MCStringRef&
11811181
}
11821182
MCAutoStringRef t_rtype;
11831183
type_to_string(self, t_htype -> return_type, &t_rtype);
1184-
MCStringAppendFormat(*t_sig, ") as %@", *t_rtype);
1184+
if (MCStringIsEqualToCString(*t_rtype, "undefined", kMCStringOptionCompareCaseless))
1185+
MCStringAppendFormat(*t_sig, ") returns nothing");
1186+
else
1187+
MCStringAppendFormat(*t_sig, ") returns %@", *t_rtype);
11851188
MCStringCopy(*t_sig, r_string);
11861189
}
11871190
break;

toolchain/lc-compile/src/grammar.g

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,26 @@
444444
'nonterm' Signature(-> SIGNATURE)
445445

446446
'rule' Signature(-> signature(Parameters, Result)):
447-
"(" OptionalParameterList(-> Parameters) ")" OptionalTypeClause(-> Result)
447+
"(" OptionalParameterList(-> Parameters) ")" OptionalReturnsClause(-> Result)
448+
449+
'nonterm' OptionalReturnsClause(-> TYPE)
450+
451+
'rule' OptionalReturnsClause(-> Type):
452+
"as" @(-> Position) TypeNoUndefined(-> Type)
453+
Warning_UsingAsForHandlerReturnTypeDeprecated(Position)
454+
455+
'rule' OptionalReturnsClause(-> undefined(Position)):
456+
"as" "undefined" @(-> Position)
457+
Warning_UsingAsUndefinedForVoidHandlerReturnTypeDeprecated(Position)
458+
459+
'rule' OptionalReturnsClause(-> Type)
460+
"returns" @(-> Position) TypeNoUndefined(-> Type)
461+
462+
'rule' OptionalReturnsClause(-> undefined(Position))
463+
"returns" "nothing" @(-> Position)
464+
465+
'rule' OptionalReturnsClause(-> optional(Position, any(Position)))
466+
@(-> Position)
448467

449468
'nonterm' OptionalParameterList(-> PARAMETERLIST)
450469

@@ -566,68 +585,74 @@
566585
-- Type Syntax
567586
--------------------------------------------------------------------------------
568587

569-
'nonterm' Type(-> TYPE)
588+
'nonterm' TypeNoUndefined(-> TYPE)
570589

571-
'rule' Type(-> named(Position, Name)):
590+
'rule' TypeNoUndefined(-> named(Position, Name)):
572591
Identifier(-> Name) @(-> Position)
573592

574-
'rule' Type(-> optional(Position, Base)):
593+
'rule' TypeNoUndefined(-> optional(Position, Base)):
575594
"optional" @(-> Position) Type(-> Base)
576595

577-
'rule' Type(-> any(Position)):
596+
'rule' TypeNoUndefined(-> any(Position)):
578597
"any" @(-> Position)
579598

580-
'rule' Type(-> boolean(Position)):
599+
'rule' TypeNoUndefined(-> boolean(Position)):
581600
"Boolean" @(-> Position)
582-
'rule' Type(-> boolean(Position)):
601+
'rule' TypeNoUndefined(-> boolean(Position)):
583602
"boolean" @(-> Position)
584603
Warning_DeprecatedTypeName(Position, "Boolean")
585604

586-
'rule' Type(-> integer(Position)):
605+
'rule' TypeNoUndefined(-> integer(Position)):
587606
"Integer" @(-> Position)
588-
'rule' Type(-> integer(Position)):
607+
'rule' TypeNoUndefined(-> integer(Position)):
589608
"integer" @(-> Position)
590609
Warning_DeprecatedTypeName(Position, "Integer")
591610

592-
'rule' Type(-> real(Position)):
611+
'rule' TypeNoUndefined(-> real(Position)):
593612
"Real" @(-> Position)
594-
'rule' Type(-> real(Position)):
613+
'rule' TypeNoUndefined(-> real(Position)):
595614
"real" @(-> Position)
596615
Warning_DeprecatedTypeName(Position, "Real")
597616

598-
'rule' Type(-> number(Position)):
617+
'rule' TypeNoUndefined(-> number(Position)):
599618
"Number" @(-> Position)
600-
'rule' Type(-> number(Position)):
619+
'rule' TypeNoUndefined(-> number(Position)):
601620
"number" @(-> Position)
602621
Warning_DeprecatedTypeName(Position, "Number")
603622

604-
'rule' Type(-> string(Position)):
623+
'rule' TypeNoUndefined(-> string(Position)):
605624
"String" @(-> Position)
606-
'rule' Type(-> string(Position)):
625+
'rule' TypeNoUndefined(-> string(Position)):
607626
"string" @(-> Position)
608627
Warning_DeprecatedTypeName(Position, "String")
609628

610-
'rule' Type(-> data(Position)):
629+
'rule' TypeNoUndefined(-> data(Position)):
611630
"Data" @(-> Position)
612-
'rule' Type(-> data(Position)):
631+
'rule' TypeNoUndefined(-> data(Position)):
613632
"data" @(-> Position)
614633
Warning_DeprecatedTypeName(Position, "Data")
615634

616-
'rule' Type(-> array(Position)):
635+
'rule' TypeNoUndefined(-> array(Position)):
617636
"Array" @(-> Position)
618-
'rule' Type(-> array(Position)):
637+
'rule' TypeNoUndefined(-> array(Position)):
619638
"array" @(-> Position)
620639
Warning_DeprecatedTypeName(Position, "Array")
621640

622-
'rule' Type(-> list(Position, ElementType)):
641+
'rule' TypeNoUndefined(-> list(Position, ElementType)):
623642
"List" @(-> Position) OptionalElementType(-> ElementType)
624-
'rule' Type(-> list(Position, ElementType)):
643+
'rule' TypeNoUndefined(-> list(Position, ElementType)):
625644
"list" @(-> Position) OptionalElementType(-> ElementType)
626645
Warning_DeprecatedTypeName(Position, "List")
627646

647+
'nonterm' Type(-> TYPE)
648+
649+
'rule' Type(-> Type):
650+
TypeNoUndefined(-> Type)
651+
628652
'rule' Type(-> undefined(Position)):
629653
"undefined" @(-> Position)
630-
654+
Warning_UndefinedTypeDeprecated(Position)
655+
631656
'nonterm' OptionalElementType(-> TYPE)
632657

633658
'rule' OptionalElementType(-> Type)

toolchain/lc-compile/src/report.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ DEFINE_WARNING(MetadataClausesShouldComeAfterUseClauses, "Metadata clauses shoul
246246
DEFINE_WARNING(EmptyUnicodeEscape, "Unicode escape sequence specified with no nibbles")
247247
DEFINE_WARNING(UnicodeEscapeTooBig, "Unicode escape sequence too big, replaced with U+FFFD");
248248
DEFINE_WARNING_S(DeprecatedTypeName, "Deprecated type name: use '%s'")
249+
DEFINE_WARNING(UsingAsForHandlerReturnTypeDeprecated, "Deprecated syntax: use 'returns <Type>'")
250+
DEFINE_WARNING(UsingAsUndefinedForVoidHandlerReturnTypeDeprecated, "Deprecated syntax: use 'returns nothing'")
251+
DEFINE_WARNING(UndefinedTypeDeprecated, "Deprecated: 'undefined' should not be used as a type")
249252

250253
////////////////////////////////////////////////////////////////////////////////
251254

toolchain/lc-compile/src/support.g

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@
295295
Error_HandlerNotSuitableForPropertySetter
296296
Warning_MetadataClausesShouldComeAfterUseClauses
297297
Warning_DeprecatedTypeName
298+
Warning_UsingAsForHandlerReturnTypeDeprecated
299+
Warning_UsingAsUndefinedForVoidHandlerReturnTypeDeprecated
300+
Warning_UndefinedTypeDeprecated
298301

299302

300303
--------------------------------------------------------------------------------
@@ -644,5 +647,8 @@
644647

645648
'action' Warning_MetadataClausesShouldComeAfterUseClauses(Position: POS)
646649
'action' Warning_DeprecatedTypeName(Position: POS, NewType: STRING)
650+
'action' Warning_UsingAsForHandlerReturnTypeDeprecated(Position: POS)
651+
'action' Warning_UsingAsUndefinedForVoidHandlerReturnTypeDeprecated(Position: POS)
652+
'action' Warning_UndefinedTypeDeprecated(Position: POS)
647653

648654
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)