Skip to content

Named instances for Core Solidity#337

Open
rodrigogribeiro wants to merge 23 commits into
mainfrom
named-instances
Open

Named instances for Core Solidity#337
rodrigogribeiro wants to merge 23 commits into
mainfrom
named-instances

Conversation

@rodrigogribeiro

Copy link
Copy Markdown
Collaborator

This PR introduces named instances for Core Solidity, following the approach used by Idris.

@Y-Nak Y-Nak force-pushed the named-instances branch from 0c1e8ea to 53c7def Compare April 14, 2026 00:32
@Y-Nak Y-Nak force-pushed the named-instances branch from 9706508 to 5ee750e Compare April 14, 2026 04:48
@Y-Nak Y-Nak force-pushed the named-instances branch from 5ee750e to 439c768 Compare May 5, 2026 11:49
@Y-Nak Y-Nak changed the title [DRAFT] - Named instances for Core Solidity Named instances for Core Solidity May 5, 2026
@Y-Nak Y-Nak marked this pull request as ready for review May 5, 2026 11:54
@Y-Nak

Y-Nak commented May 5, 2026

Copy link
Copy Markdown
Member

Comment thread src/Solcore/Frontend/TypeInference/TcStmt.hs Outdated
Comment thread src/Solcore/Frontend/TypeInference/TcStmt.hs Outdated

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an instance has the same name as a function, the compiler says the name is undefined, e.g.

// named instance/function name conflict

forall a.class a:C {}

instance [foo] word : C {}

function foo(x:word) { 7 }

contract Clash {
  function main() -> word {
    return foo(1);
  }
}
Module validation failed for /home/ben/work/review/tmp/named4.solc:
Undefined name: foo
 - in:return foo(1) ;
 - in:function main () -> word {
   return foo(1) ;
}

Comment thread src/Solcore/Frontend/Parser/SolcoreParser.y Outdated
@mbenke

mbenke commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Nicely done. I do not want to appear nitpicky but there still are some problems with case sensitivity:

forall a . class a : Eq {
  function upperScore(x : a) -> word;
}

forall a . class a : eq {
  function lowerScore(x : a) -> word;
}

forall a . a : Eq, a : eq => function useBoth(x : a) -> word {
  return Eq.upperScore(x);
}

instance [upperEq] word : Eq {
  function upperScore(x : word) -> word {
    return 1;
  }
}

instance [lowerEq] word : eq {
  function lowerScore(x : word) -> word {
    return 2;
  }
}

contract NamedInstSlotOrderSensitivity {
  function main() -> word {
    return useBoth@{eq = lowerEq, Eq = upperEq}(1);
  }
}

yields

test/examples/cases/named-inst-slot-order-sensitivity.solc
Constraint slot eq matches multiple wanted constraints for useBoth
Use a class name with exact capitalisation to disambiguate.

Of course it is not a good idea to have class names differing only in capitalisation, but I can imagine this happening with imports.

@Y-Nak

Y-Nak commented May 19, 2026

Copy link
Copy Markdown
Member

@mbenke Thank you for the review; it's helpful.
I fixed the issue that you found. Would you review it again?

@Y-Nak Y-Nak requested a review from mbenke May 19, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants