Open TheBlueSky opened 4 months ago
This is working as intended but what's going on isn't intuitive.
C# Scripting doesn't allow you to redefine an existing method (though it does allow you to shadow one if it has the same signature). When you run the cell defining Function(params string[] args)
and then again defining Function(string name, params string[] args)
, you're effectively adding an overload of Function
. Both of them exist simultaneously in the notebook's backing compilations, resulting in this:
Function(); // calls Function(params string[] args)
Function("a"); // calls Function(string name, params string[] args)
Function("a", "b", "c"); // calls Function(string name, params string[] args)
When you restart the kernel, Function(params string[] args)
no longer exists, so the call to Function()
no longer compiles.
Thanks for your response, @jonsequitur, and the clear explanation. I appreciate it.
C# Scripting doesn't allow you to redefine an existing method
Could you kindly explain the reason?
C# Script creates an assembly for each code submission (which in the notebook corresponds to each time you run a cell.) Later submissions don't cause the earlier submissions to be recompiled. They're immutable.
Changing a pre-existing compilation isn't allowed because it could cause subsequent assemblies to no longer be bound correctly. It would put the program into an invalid state if you could remove a declared method (or any other symbol). Removing a method is effectively what would have been happening if re-running your cell containing the Function
method caused the original definition to be changed.
Describe the bug
It is easier to describe the behaviour with code than writing 😅
.ipynb
Notebook and C# as the kernel)error CS7036: There is no argument given that corresponds to the required parameter 'name' of 'Function(string, params string[])'
.Please complete the following:
Which version of .NET Interactive are you using?
Screenshots
None required.