Proposed: Include '?' suffix for compatibility purposes.

Issue #52 closed
Winter Laite created an issue

Possibly refer to this docs page.

The '?' suffix can be used to specify parameters as optional, as below.

Greet("Greeting")  ; MsgBox title is "Greeting"
Greet()             ; MsgBox title is A_ScriptName

Greet(title?) {
    MsgBox("Look at the MsgBox title!", title?)
}

This can of course be easily converted to existing Keysharp syntax, as below.

Greet("Greeting")  ; MsgBox title is "Greeting"
Greet()             ; MsgBox title is A_ScriptName

Greet(title := "") {
    MsgBox("Look at the MsgBox title!", title)
}

Comments (6)

  1. Matt Feemster repo owner

    I’ve committed a fix. If you enter this in Keyview with and without the ?, you’ll see the change in code it generates.

  2. Winter Laite reporter

    Fails in Keyview, fails in Keysharp. Error:

    Compiling C# code to executable failed: 
    The following errors occurred:question_52.ahk:: (120,45)-(120,46) - Invalid expression term ')' 
    question_52.ahk:: (120,45)-(120,46) - Syntax error, ':' expected 
    question_52.ahk:: (120,45)-(120,46) - Invalid expression term ')' 
    question_52.ahk:: (120,39)-(120,44) - Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?) 
    

  3. Matt Feemster repo owner

    The reason the first does not work is that I am not supporting referring to the variable with the ? suffix within the function. The parameter has the ? suffix to indicate it’s optional, wowever, I don’t think it makes sense to also use the parameter within the function with the ? attached.

    I know the documentation says: “To pass an optional parameter through to another function even when the parameter has no value, use the maybe operator (var?).”

    However this is not going to be necessary or supported in Keysharp. So mark this one closed and I’ll add it to our list of differences.

  4. Log in to comment