cron icon indicating copy to clipboard operation
cron copied to clipboard

cron.New().Remove()

Open tuye01 opened this issue 2 years ago • 1 comments

code: id := 1 cron.New().Remove(1) cron.New().Remove(id) question:

  1. The parameter requirement is EntryID, why is 1 possible?
  2. 1 There is no error, why can't the id?

tuye01 avatar Oct 11 '23 09:10 tuye01

Hi @tuye01 it's probably a matter of type inference.

The parameter requirement is EntryID, why is 1 possible?

Here you're assigning the numeric literal directly to the argument and therefore the inferred (or implicitly converted?) type corresponds to the required one. This is possible because cron.EntryID is an alias typedef for int.

There is no error, why can't the id?

While here you first assign the literal to id, which makes the variable have type int and then when you call cron.New().Remove(id) the types do not match.

In fact, if you explicitly type the variable var id cron.EntryID = 1 the removal runs as expected.

janrnc avatar Oct 13 '23 22:10 janrnc