Greetings,
As per the requirement before putting together a proposal, a discussion on LHS inference for type assertions
Currently, type assertions take the form of:
//
// Pre assertion
//
var original string = "Hello Type Assertions"
var data interface{} = original // or "var data any"
//
// Assertions
//
// fails compiler checks
destInt := data.(int)
// passes compiler checks
destString := data.(string)
Proposal:
Instead of a RHS type assertion, I'd like to propose a language change that would take the type assertion as an inference from the LHS, potentially using a new assignment operator.
//
// Pre assertion
//
original := "Hello Type Assertions"
var data interface{} = original // or var data any
// LHS inference of the int type. Compiler checks fail. (notice the ".=" assignment operator, it could be variation of the assignment operator that makes it clearer)
var destInt int .= data
// LHS inference of the string type.
var destString string .= data
// or
var destString string
destString .= data
This could potentially work with multiple RHS returns too.
var data string
var err error
data, err .= function()
I'm certainly no programming language expert but does this hold any value?