Repository navigation
fix(hy-syntax,hy-emit): keep fn-type result parsing on same line and support unnamed/parenthesized signatures (fixes #727) - #735
Open
aazminu wants to merge 2 commits into
Conversation
…support unnamed/parenthesized signatures (fixes limitlessprojects#727)
…/aliased fn callees (limitlessprojects#727)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #727.
Previously,
Parser::parse_type'sTok::Kw("fn")arm collected result types via an unguardedwhile self.is_type_start()loop that crossed line boundaries, and usedparse_params()(which requires a leading parameter identifier) forTypeExpr::Fnparameter lists:var cb fn() intfollowed on the next line byfmt.println(cb == nil)orf(1)absorbed the following line's leading identifier/type intoTypeExpr::Fn.results, either swallowing the next statement or turning it into a multi-returnfunc() int, ...Go syntax error.structdeclaration, any field declared after afn(...)-typed field (e.g.on_event fn(int) boolfollowed byname string) had its field name and type absorbed as extra return types of thefnfield, erasing the subsequent struct field.fn(int) boolorfn(*int, []string) (int, error)were either stored inParam.namewith an emptyParam.ty(causinghy-emitto emit a trailing spacefunc(int )and bypassing checker passes onParam.ty) or rejected when starting with*/[/<-.hy-emit(TypeExpr::Fnwithresults.len() > 1) were emitted without parentheses (func() int, error) instead of valid Gofunc() (int, error).Changes
compiler/crates/hy-syntax/src/parser.rs:TypeExpr::Fnresult parsing withself.same_line_as_prev()so identifiers/types on following lines (next statements or subsequent struct fields) are never absorbed intoresults.if self.same_line_as_prev() && self.at_punct("(")) viaparse_results().parse_fn_type_params()(and alignparse_results()) so unnamed parameter types (fn(int),fn(*int, []string, map[string]int)) populateParam.tywith an emptyParam.namewhile named parameter lists (fn(a int, b string)) continue to populate bothParam.nameandParam.ty.compiler/crates/hy-emit/src/lib.rs:TypeExpr::Fnparameters without a leading/trailing space, parenthesize multi-valueTypeExpr::Fnresult lists (func(...) (T1, T2)), and return"nil"as the zero value forTypeExpr::Fn.compiler/crates/hy-check/src/buildable.rs:Some(params.len())inkind_of_ty_with_substforTypeExpr::Fn.hy-syntax,hy-emit, andhy-checkcovering all reproducer shapes from [soundness] hy-syntax: afn(...) Ttype absorbs identifiers on the following lines as extra result types:var cb fn() intswallows the next statement (accepted, emitted Go is a syntax error); struct fields after a fn-typed field disappear #727.