diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 0c29474..270dd5a 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -400,8 +400,9 @@ impl Parser { Tok::Eq | Tok::Colon if depth == 0 => { let mut shape = vec!["let".to_string(), name.clone()]; if parenthesized && params.is_empty() { - // `def greet():` takes no arguments, which Pyfun spells `()`. - params.push("()".to_string()); + // `def greet():` takes no arguments: Pyfun gives it one it + // ignores (`let greet _ = …`), called as `greet ()`. + params.push("_".to_string()); } shape.extend(params); return Some(ParseError { diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index 653a20d..dd40c4c 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -781,7 +781,7 @@ fn def_is_answered_with_the_let_spelling() { "def area(w: int, h: int) -> int:\n w * h", "write `let area w h = …`", ), - ("def greet():\n print \"hi\"", "write `let greet () = …`"), + ("def greet():\n print \"hi\"", "write `let greet _ = …`"), ("let f x =\n def g y = y + 1\n g x", "write `let g y = …`"), ] { let err = parse(source).unwrap_err(); @@ -791,6 +791,9 @@ fn def_is_answered_with_the_let_spelling() { err.message() ); } + // Every suggested spelling parses. + assert!(parse("let area w h = w * h").is_ok()); + assert!(parse("let greet _ =\n print \"hi\"").is_ok()); // `def` is still an ordinary identifier: a function the program calls `def`. assert!(parse("let def x = x + 1\nprint (def 2)").is_ok()); }